Serve Ghost and Nginx on Ubuntu 14.04 LTS

Recently I switched from Linode to DigitalOcean because of some rumor that Linode website is blocked in China. Here is a memo of how I migrated a Ghost blog,

Some content came from several tutorials from DigitalOcean community. Credits are given at the end of this article.

Install Nginx

Install Nginx via apt-get.

sudo apt-get update
sudo apt-get install nginx

Create Site Directories

I prefer /var/www as the root directory. To do that I created the following folders to hold my website files.

sudo mkdir -p /var/www/
sudo mkdir -p /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www

Create Server Block Files

Server blocks configure ports and root directories for each website, as well as details about how they should be served.

Here I used as the default domain of my server.

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/
sudo vim /etc/nginx/sites-available/

Change the configuration like this:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/;
    index index.html index.htm;


    location / {
        try_files $uri $uri/ =404;

Then I created the second server block file for Since it is a Ghost blog, the file should be like this:

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

The files are done but we are not done. Enable the server block files.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Delete the default site generated by Nginx.

sudo rm /etc/nginx/sites-enabled/default

Restart Nginx to apply new settings.

sudo service nginx restart

Install Ghost

Prerequisites first. Ghost requires Node.js and npm. These can be installed in various ways. Refer to this article for more options.

sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

Download Ghost. Details about the remaining steps in this chapter can be found in the official guide at

sudo apt-get update
sudo apt-get install zip wget

cd /var/www/
sudo wget
sudo unzip -d ghost

Install it.

cd ghost/
sudo npm install --production

Configure Ghost

Change the url and/or port under production section.

sudo cp config.example.js config.js
sudo vim config.js

I also needed to migrate data, images and themes. Copy or replace them under content/.

Keep Ghost Running

Create upstart configurations to make the ghost blog start on system boot. In this way I can also manage my ghost blog as a service.

sudo /etc/init/vim ghost-otakism.conf

Paste the following lines.

# ghost-otakism

start on startup

    cd /var/www/
    npm start --production
end script

Finally I can summon my ghost.

sudo service ghost-otakism start

Contents about Nginx setup credits to Justin Ellingwood, original post at How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS.