Here we will introduce how to install Node. js and Ghost in Ubuntu 14.04 LTS.
1. Install Node. js
To maintain the latest version, we use the PPA format. You can directly use this script to import PPA:
Sudo curl-sL https://deb.nodesource.com/setup | sudo bash-
After the import is complete, directly install Node. js
Sudo apt-get install nodejs
This Node. js package already contains npm, so you don't need to install npm separately, and some Node. js programs have to install the build-essential package separately. You can also install it:
Sudo apt-get install build-essential
Check the Node. js and npm versions after installation.
Root @ example :~ # Node-v
V0.10.33
Root @ example :~ # Npm-v
1.4.28
Ghost must run in Node. js version 0. 10.
2. Download the Ghost program
Based on security considerations, you can create a new ghost user. Here we install it in the/var/www/directory.
Useradd ghost
Mkdir/var/www
Cd/var/www
Curl-L https://ghost.org/zip/ghost-latest.zip-o ghost.zip
Unzip ghost.zip
Chown-R ghost: ghost/var/www
In this way, the permissions are set and the Ghost is downloaded.
3. Install and configure Ghost
First install with npm
Npm install -- production
Note that there are two minus signs
After npm is installed, enter this command to enable Ghost to start in developer mode.
Npm start
Then you can view the established Ghost blog from http: // 127.0.0.1: 2368/on the local machine. Because we are installed on the server, your local browser cannot be accessed, press Ctrl + C to stop. A config will be generated at this time. js, and then modify config. js
Change the url: 'http: // my-ghost-blog.com 'to your domain name, such as url: 'http: // example.com ',
After the installation is complete, we need to keep the Ghost running in the background and configure the Nginx Reverse proxy for Internet access.
4. Keep the Ghost running in the background + enable startup
There are two methods
1. Run Ghost tasks after using forever
Install forever
Npm install forever-g
Run Ghost
NODE_ENV = production forever start index. js
Then, you can use forever stop index. js to stop Ghost.
You can also use the forever list to check whether the Ghost is running.
2. Run Ghost in the Supervisor background and start it on startup
Install Supervisor
Sudo apt-get install supervisor
Create a Ghost startup script file, for example,/etc/supervisor/conf. d/ghost. conf. Edit the file as follows:
[Program: ghost]
Command = node/var/www/index. js
Directory =/var/www
User = ghost
Autostart = true
Autorestart = true
Stdout_logfile =/var/log/supervisor/ghost. log
Stderr_logfile =/var/log/supervisor/ghost_err.log
Environment = NODE_ENV = "production"
Restart the Supervisor to take effect.
Service supervisor restart
You can also use the Supervisor to start Ghost.
Supervisorctl start ghost
Then we start to install Nginx and configure the reverse proxy for local access.
4. Install Nginx to configure reverse proxy
First install Nginx
Sudo add-apt-repository ppa: nginx/stable
Sudo apt-get update
Sudo apt-get install nginx-extras
Modify/etc/nginx/sites-available/default
Server {
Listen 80;
Server_name example.com;
Location /{
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ remote_addr;
Proxy_set_header Host $ host;
Proxy_pass http: // 127.0.0.1: 2368;
}
Location ~ *\.(? : Ico | css | js | gif | jpe? G | png | ttf | woff) $ {
Access_log off;
Expires 30d;
Add_header Pragma public;
Add_header Cache-Control "public, mustrevalidate, proxy-revalidate ";
Proxy_pass http: // 127.0.0.1: 2368;
}
Location =/robots.txt {access_log off; log_not_found off ;}
Location =/favicon. ico {access_log off; log_not_found off ;}
Location ~ /\. Ht {
Deny all;
}
}
Save and restart Nginx
Sudo service nginx restart