How to Host Ghost on a Nginx Subdomain


If you currently have a website running on an Nginx web server and you are interested in installing Ghost on a subdomain this walk through will detail how to setup it up. After this tutorial you will have your main domain (we will use the domain example.com) served by Nginx and your Ghost blog on a subdomain (blog.example.com) served by Node.js.

The Nginx default location for your website is /usr/share/nginx/html so we are going to stick with that. We are going to make the primary website in the directory /usr/share/nginx/html/example.com and the Ghost blog in /usr/share/nginx/html/blog.example.com.

To tell Nginx about your new blog we need to edit the Nginx default.conf file. The file by default is located at /etc/nginx/conf.d/default.conf. Edit that file:

 sudo vi /etc/nginx/conf.d/default.conf

Now at the very bottom of the file add in the following (changing the server_name to your site):

 #Following section for blog.example.com
 server {
     listen 80;
     server_name  blog.example.com;

     location / {
             proxy_pass http://127.0.0.1:2368/;
             proxy_set_header Host $host;
             proxy_buffering off;

     }
 }
You can reference our sample Nginx default.conf file for help.

Once that is saved we need to restart Nginx so that it will load these changes.

sudo service nginx restart

Now in your browser you can open your blog subdomain, blog.example.com, and Node.js will serve your Ghost blog!