How To Proxy Multiple Ghost Blogs Through Nginx


Nginx is the recommended way to proxy requests for Ghost. By default, the config file for Nginx lives in /etc/nginx/sites-available/. Open up your existing conf file or create a new ghost.conf file in that folder.

With Nginx, inside the conf we create separate server blocks. One for each blog. If we have two domains coming in, sales-blog.com and marketing-blog.com, this is what that config would look like:

server {
    listen 80;
    server_name sales-blog.com;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:2368;
    }
}

server {
    listen 80;
    server_name marketing-blog.com;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8080;
    }
}

Notice also that in the proxy_pass section, the ports are different after the ip. These need to be the specific ports that each Ghost blog is running on.

Restart Nginx. On most setups this should work:

service nginx restart

If not, try this command:

/etc/init.d/nginx restart

You should now be able to go to either url and see the correct Ghost blog! If you run into any trouble with creating a new Nginx setup or for help with file locations, checkout this ServerFault question.