How to configure Ghost with Nginx (Centos/RHEL)

04 Jan 2015

This tutorial will guide you on how to setup Ghost blog with Nginx as reserve proxy.

Nginx is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer, HTTP cache, and a web server (origin server).

OS Setup

First step is to update Ubuntu and create non-root user to run your Ghost app.

Update Ubuntu packages to stable releases:

[gtheme_io@tutorial ~]# sudo yum update -y

Install required package:

[gtheme_io@tutorial ~]# sudo yum install git unzip -y

Install cc and g++ for 64bit CentOS:

[gtheme_io@tutorial ~]# sudo yum  install gcc gcc-c++ -y

Create Ghost User

Install Ghost Blog

Next step is to prepare NodeJS runtime environment. You are recommend to install nvm to manage multiple NodeJS versions. The following shows how to install nvm.

[gtheme_io@tutorial ~]# curl | bash

## reload profile
[gtheme_io@tutorial ~]# source ~/.bash_profile

After install nvm, now we will install latest NodeJS:

[gtheme_io@tutorial ~]# nvm install v0.10
[gtheme_io@tutorial ~]# nvm alias default v0.10
[gtheme_io@tutorial ~]# nvm use v0.10

Note: nvm will automatically use latest v0.10.x version.

Next step is to download Ghost app and install:

## download ghost blog
[gtheme_io@tutorial ~]# wget

## unzip ghost archieve
[gtheme_io@tutorial ~]# unzip -d ghost
  inflating: ghost/Gruntfile.js      
  inflating: ghost/index.js          
  inflating: ghost/package.json

Next you can start to install Ghost Blog:

[gtheme_io@tutorial ghost]# cd ghost    
[gtheme_io@tutorial ghost]# npm install --production

Finally, start Ghost:

[gtheme_io@tutorial ghost]# npm start

Install Nginx

Next step is install Nginx for reverse proxy Ghost blog. For CentOS the first thing you will need to do is create a Nginx yum repository: [gtheme_io@tutorial ghost]# vim /etc/yum.repos.d/nginx.repo

and then paste the following into that file:

name=nginx repo baseurl=$releasever/$basearch/gpgcheck=0

Now that yum knows where to download Nginx you can install it with:

[gtheme_io@tutorial ghost]# sudo yum install nginx -y
[gtheme_io@tutorial ghost]# sudo service nginx start
[gtheme_io@tutorial ghost]# sudo chkconfig nginx on

Configure Nginx

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/. We would recommend creating your configuration file in this directory and naming it something meaningful, like: Once you have created your new Nginx conf file place the following into your file, replacing with your domain name:

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

After configured Nginx, you can restart Nginx to use new configuration:

[gtheme_io@tutorial ghost]# sudo service nginx restart

Now your Ghost blog is accessible via default HTTP port(80) and proxy to Ghost's default port 2368. Happy blogging!