The complete guide to self-hosted Ghost blog on Ubuntu/Debian

Written on 04 June 2016

I have used Ghost for year. I Install Ghost in Debian with Node LTS 4 and Nginx server.

Stack : Nodejs, Nginx, Sqlite,Debian, Systemd
1. Prepair to install Ghost
You need to install Nodejs , the best is Node LTS version

cd /tmp  
// For x86 
wget -O node.tar.gz  
// For 64
wget -O node.tar.gz

 sudo  tar --strip-components 1 -xzvf node.tar.gz  -C /usr/local
//Test Node
node -v && npm -v  
// Sample result

2. Install dependencies package

apt-get update  
apt-get install build-essential unzip  

3. Download latest Ghost version

mkdir -p /var/www/ghost  
wget -O  
unzip -d /var/www/ghost  

4. Install Ghost

npm install --production,  
npm start --production  
// change file owner
chown www-data:www-data -R /var/www/ghost  

Then edit config of production

   // ### Production
    // When running Ghost in the wild, use the production environment.
    // Configure your URL and mail settings here
    production: {
        url: '',//Your url here
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            debug: false

        server: {
            host: '',
            port: '2368'

5. Setup Ghost as Proxy server behind Nginx

upstream ghost {  
    server http://localhost:2368;
    #keepalive 64;
proxy_cache_path /var/cache/nginx/blog levels=1:2 keys_zone=BLOG:75m inactive=24h max_size=512m;  
server {  
 access_log   /var/log/nginx/;
        error_log    /var/log/nginx/example.error.log;

   add_header X-Cache $upstream_cache_status;
   location / {
        proxy_cache BLOG;
        proxy_cache_valid 200 30m;
        proxy_cache_valid 404 1m;
        proxy_pass http://ghost;
        proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
        proxy_ignore_headers Set-Cookie;
        proxy_hide_header Set-Cookie;
        proxy_hide_header X-powered-by;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        expires 10m;
    location /content/images {
        alias /var/www/ghost/content/images;
        access_log off;
        expires max;
    location /assets {
        alias /var/www/ghost/content/themes/current/assets;
        access_log off;
        expires max;
    location /public {
        alias /var/www/ghost/core/built/public;
        access_log off;
        expires max;
    location /ghost/assets {
        alias /var/www/ghost/core/built/assets;
        access_log off;
        expires max;
    location ~ ^/(?:ghost|signout) { 
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://ghost;
        add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";


Then run command bellow to make site enable

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enable/  
sudo service nginx reload  

6. Run Ghost as a service use systemd

cd /etc/systemd/system  
vim ghost.service  

Then paste this

Description=Ghost blog

ExecStart=/usr/local/bin/npm start --production  
ExecStop=/usr/local/bin/npm stop --production  
SyslogIdentifier=Blog Ghost


Enable ghost service

systemctl enable ghost.service

systemctl start ghost.service  

Now start blogging :)