Hosting Ghost blog without NginX or Apache - node.js

I've decided to take the plunge and make my next blog in Ghost 0.4.1 rather than Wordpress. My client has a VERY small amount of traffic, and it is easy to say that they will never need to be load balanced across multiple servers.
My question is:
Ghost can be configured to listen to a certain port, so can I use it as my web server listening to port 80? Is there a problem to doing this?
Followup Question:
Every example shows hosting it with Apache or NginX, is there a security or performance reason for this?
Thanks in advance!

You definitely can run Ghost on port 80 but it is recommended to run Ghost on port 2368 and proxy requests through Apache or Nginx.
You can checkout this article for an example of how to install Ghost and run it on port 80. But I would highly recommend reading through this article and proxying requests through Nginx. With Ghost running on port 2368 you can use a low privileged user to start Ghost and therefore will not have to use a higher privileged user to start Ghost.

Yes. But you must run Ghost under root privilege or add ghost to sudoers
server: {
host: '0.0.0.0',
port: '80'
}
I tried and it worked.

Related

How to link node+express server to domain

I have a domain name pointing to my vps IP. But when I run my express server I have to set a port, usually I use 3000, so the only way to get in my website is specifying the port: www.mysite.com:3000.
How can I make my app run in my domain without adding any port? My first guess was setting also the port in my domain name provider (111.11.11.11:3000) but Godaddy doesn't let me to add the port.
How can I make it work?
Newbie question, I know, but i'm a first timer and haven't found any answer to this.
The correct way is to change the port its hosted on. The default port for http traffic is 80, the one for https is 443. I assume you are on linux, if so you need to give some special permissions as ports below 1024 are privileged ports.
TLDR: if running http, change your express config to 80, if https 443
If using express, you need to change express port from 3000 to 80 if you plan using HTTP or 443 if you plan using HTTPS.
This is assuming your VPS does not already use port 80 or 443 while running an HTTP server like apache or nginx.
If you are in this case you will need to set up a reverse proxy.
I went for Nginx solution, I could make the port forward really easy following this guide:
https://eladnava.com/binding-nodejs-port-80-using-nginx/
For those who face this problem, solution is much more easier than it could look at beginning.

Best practice for communicating with a NodeJS server hosted locally from a Bluehost NodeJS server?

I have a web application running on a Bluehost server. I am trying to retrieve files hosted on a local server. On the local server, I have port forwarding and NodeJS listening on port 3000. I could do 80 as well, but from what I have read, that is not safe.
The issue I am running into is mainly the SSL cert for the local Node instance. The web application requires post requests to be made to https:// sources.
What are some best practice approaches to making this work? I have heard about installing Apache and running a ProxyPass to port 3000, but I am still concerned that the port 80 will have no SSL. Any help would be appreciated!!
First its worth noting that there are many approaches to hosting a web service.
Node can handle https connection, you should read the native https module documentation for how this works.
I tend to use Nginx (although apache is great and is a battle-tested solution) as a proxy server to node as, in general, I find it speeds up the process to get a product live. It also allows you to extract potential requirements from your node server, such as caching and SSL, so your node app can just focus on business requirements.
If you go for a proxy server, Nginx (and others), have modules that will handle SSL certificates. Lots of documentation online about how to set this up.
Something to keep in mind is that PORT 80 and 3000 are connection points for traffic. You will only be able to interact with the server on these ports if you bind and expose an application to them. If nothing is exposed to PORT 80, then connect attempts will just fail.
The best practices I tend to employ are:
No excuse not to use SSL nowadays, the standard is to expose https server on port 443.
If you choose to expose port 80, redirect all traffic to 443. This guarantees a secure connection.

How to access local web server from another computer

I know this may be asked in different threads, but I really couldn't find a solutions for my simple problem.
I have a web server (Ubuntu) on port 4000 running and I want to access it from my second computer (same network). I don't mind if it's exposed to the Internet (it's only temporally).
I can ping the web server computer, but port 4000 is not reachable.
Can some give me a simple solution for this problem? That would make my day.
EDIT:
I run jekyll serve
EDIT:
Okay I found a really helpful blog entry for solving my problem.
link
If you are running Apache2 webserver edit your configuration like this:
From:
Listen 127.0.0.1:4000
To:
Listen 4000
See https://httpd.apache.org/docs/current/en/bind.html for reference.
Configuration examples for nginx are available here: https://nginx.org/en/docs/http/ngx_http_core_module.html#listen
Restart/reload your apache2 or nginx service to apply configuration changes.
Your webserver is now reachable through http://[webserverip]:4000

Hosting PHP and Node.js apps on the same server with multiple domains

I have a Linode VPS, currently running lighttpd to serve up my PHP websites and listening on port 80.
I'm also running Node.js, which listens on port 81, and uses websockets and HTTP to interact with the client.
There's a couple of different domains that I would like to point to this server. Ideally, I would like the domains which host the PHP sites to all talk to the same lighttpd server, and the sites which use node.js would somehow redirect to the port node.js is listening on unbeknownst to the client (e.g. no 30x redirect).
example-php1.com:80 -> linodebox:80 lighttpd /var/www/example1
example-php2.com:80 -> linodebox:80 lighttpd /var/www/example2
example-node.com:80 -> linodebox:81 node.js
Is there a way to do this, either by setting DNS entries or tweaking iptables? Does lighttpd need to be a proxy for node.js? The websockets feature needs to work without any fallbacks, and visiting a non node domain, e.g. example-php1.com:81, should not expose the node application.
I feel the perfect solution wouldn't require changes to existing application code nor require proxying between software web servers, but I could be wrong.
What's up Tom!?
I recommend HA-Proxy, it's one of the most high performance proxies out there and should accomplish what you're trying to do there.
I'm doing something similar with nginx acting as a proxy, it's easy but not the fastest.
HA-Proxy's website is here http://haproxy.1wt.eu
If you wanted a 'pure' solution, you could probably get the answer from looking at ha-proxy's source code. You can't really do it with iptables. Something has to read the HTTP header to determine where the request came from to route it locally.
I had basically the same problem and I ended up using node-http-proxy (also available in npm as http-proxy).
You just need a simple config file:
{
router: {
'example-php1.com': 'linodebox:80',
'example-php2.com': 'linodebox:80',
'example-node.com': 'linodebox:81
}
}
Then just run node-http-proxy --config options.json and you're set. If you want to run lighttpd and node on the same machine, you'll have to start lighttpd on a different port (I use 81 for php and 3000 for node - adjusting the config is easy). I also use forever to manage my node instances.
Ya'll are gonna hate me...
I ended up going with a second IP address, then followed the Linode tutorial to setup multiple static IPs. Then, I configured lighttpd to bind to one IP address and Node.js to bind to another IP address.
This isn't a great solution as it doesn't scale.
Update: lighttpd 1.4.46 (released back in 2017) added multiple ways to accept WebSocket connections:
lighttpd mod_wstunnel
lighttpd mod_proxy
lighttpd mod_cgi

How do IP addresses work on a VPS? Routing a domain name to Node.JS

This is an absolute newb question. But I'm buying my first VPS for the reason that I want to install and start creating applications in Node.JS.
I can't visualise in my mind how the server works and where all of the applications such as Apache, Node.JS and PHP sit. I'm so used to a GUI.
I want www.mydomain.com to point to node.JS on my server, let's say Node is listening to port 8080. Now I know that HTTP defaults to port 80 of the IP address, so I can't use that. How do I set the domain up to resolve at www.mydomain.com:8080 - I read this wasn't possible...
My brain is melting.
Thanks :)
You just point the domain to your ip address as you normally do. The issue you will have it that HTTP default to port 80, so either you manually add the port at the end of the host to get to the page or you setup Apache to proxy specific urls to 8080, which gets some of your Node stuff appearing to work under 80.
If you aren't using Apache for anything you can also have your Node app bind to port 80. You will probably need to setup authbind or something to give your node app permission to bind to port < 1024.

Resources