Sharing space - Setting up Ghost behind a proxy - Nginx

In my last blog post I explained how to set up a Ghost blog behind a proxy using Apache as the proxying server. This post is just a quickie to explain how to do the same with Nginx

If you haven't done so you can set up node.js and Ghost by following the previous tutorial

Step 1 - Locating your nginx install

If you've installed your nginx server recently or using your distro's package manager you'll likely have a good idea of where your nginx folder is. However, if you've compiled from source you might not have caught where it's been installed to. We'll be creating files in the 'sites-available' directory so first we'll find where that is:

  locate nginx/sites-available

The output of this command should give you the full path to your nginx install as well as any conf files in that directory. Within that directory we need to create a new .conf file to tell our server where to pass requests. Load up your favourite text editor and create a new file called ghost.conf:

  nano nginx-path/sites-available/ghost.conf

In this file we're going to put the following:

  server {
    listen 80;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;

This file opens up a server block, which listens on the default HTTP port for incoming connections and sends the requests for to our ghost install. Unlike Apache, we don't have to enable or set the proxy module as it is already enabled by default.

After that we need to enable our new site config in nginx:

  ln -s nginx-path/sites-available/ghost.conf nginx-path/sites-enabled/ghost.conf

Then just restart nginx and navigate to the domain you put in the server_name directive:

  service nginx restart

Et voila!

Test Ghost blog up and running

Think we can help with your web site or app project?

Let’s Chat