Ghost platform integration into Ubuntu 16.04 Nginx - proudcloud/awesome GitHub Wiki

Update package source & install Nginx.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install nginx

Install mysql-server. Set root password. !important

$ sudo apt-get install mysql-server

Install Node.

$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash 
$ sudo apt-get install -y nodejs

Install Ghost CLI.

$ sudo npm i -g ghost-cli

Create working directory for Ghost. It should be outside root or user home scope. !important

$ sudo mkdir -p /var/www/ghost

Grant deploy user with this directory & set appropriate perms.

$ sudo chown deploy:deploy /var/www/ghost
$ sudo chmod 775 /var/www/ghost

Set server’s firewall/security group to whitelist inbound port 2368 which will be used by Ghost.

Go to directory and install Ghost with the following prompt responses

$ cd /var/www/ghost
$ ghost install

Answer the following prompts, noting http/https for blog URL is vital whether or not it will prompt to setup SSL later. See https://docs.ghost.org/docs/cli-install#section-prompts . For now we assume that SSL is already setup for the domain.

? Enter your blog URL: https://myapp.com/blog 
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your Ghost database name: ghost_prod
? Do you wish to set up "ghost" mysql user? Yes
? Do you wish to set up Nginx? No
? Do you wish to set up Systemd? Yes

Add Nginx config for Ghost. Add this for both server block that listens to 80 & 433 & appropriately set proxy_pass protocol.

# /etc/nginx/sites-enabled/myapp
  location ^~ /blog {
    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;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass https://127.0.0.1:2368;
    proxy_redirect off;
  }

Restart nginx & verify https://myapp.com/blog

$ sudo service nginx restart

Further troubleshooting visit https://docs.ghost.org/docs/troubleshooting or run

$ ghost doctor