How to Proxy Port 80 to 2368 for Ghost with Nginx

If you followed one of our posts on How To Install Ghost, we highly suggest going through this post right after installing Ghost so that your Ghost blog is accessible on port 80 instead of 2368. We will accomplish this by using Nginx to proxy all requests for port 80 to 2368. So to start, install Nginx with one of the following commands, depending on what operating system you are running:
CentOS
For CentOS the first thing you will need to do is create a Nginx yum repository:
vim /etc/yum.repos.d/nginx.repo
and then paste the following into that file:
[nginx]
name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
Now that yum
knows where to download Nginx you can install it with:
sudo yum install nginx -y
sudo service nginx start
sudo chkconfig nginx on
Ubuntu
sudo apt-get install nginx -y
With Nginx installed, we now need to tell Nginx that Ghost is ready for requests on port 2368. New Nginx configuration files can be added into /etc/nginx/conf.d/
(CentOS) or /etc/nginx/sites-enabled
(Ubuntu). We would recommend creating your configuration file in this directory and naming it something meaningful, like: your-domain-name.conf
. Once you have created your new Nginx conf file place the following into your file, replacing your-domain-name.com
with your domain name:
server {
listen 80;
server_name your-domain-name.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
If you find sample Nginx configuration files found in /etc/nginx/conf.d/
or /etc/nginx/sites-enabled/
, I would recommend deleting them.
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default
rm /etc/nginx/conf.d/default
Now restart Nginx to make your changes take affect:
CentOS and Ubuntu
sudo service nginx restart
Your Ghost blog is now reachable via your domain name, on port 80, through Nginx to port 2368.