文章目录
  1. 前言
  2. 安装 Node.js
  3. 准备Ghost文件
  4. 安装Ghost
  5. 使用Forever托管Ghost
  6. 使用Nginx反向代理Ghost

前言

Ghost是一款简洁的、功能强大的基于 Node.js 的博客程序,创始人的目标就是替代臃肿膨大的WordPress成为最流行的写作程序。
按照这篇文章,你只需要一台运行内存>=512m运行内存的VPS(经测试128m内存vps也可以流畅运行),即可快速搭建出属于你自己的博客。

本文使用的是512m内存 运行ubuntu 14.04 X64的VPS

安装 Node.js

curl -sL https://deb.nodesource.com/setup
导入完PPA以后即可安装 Node.js和NPM apt-get install nodejs apt-get install npm
为防止某些程序不能运行,需要安装编译环境build-essentials(可能会自带)
apt-get install build-essential

运行Node.JS的时候请一定要注意,因为与别的工具包相冲突的原因,Ubuntu仓库中可执行的名字是nodejs而不是node。

所以我们需要自己创建软连接,否者后续的安装无法继续
ln -s /usr/bin/nodejs /usr/bin/node

准备Ghost文件

建立安装目录 

mkdir /home/Ghost cd /home/Ghost
curl -L http://ghost.org/zip/ghost-latest.zip
unzip ghost-latest.zip

至此Ghost所需的环境和安装文件都已经准备完成了。

安装Ghost

npm install --production

尝试在开发者模式下运行npm start

由于我们是安装在VPS,所以并不能通过http://127.0.0.1:2368/ 来查看网页

现在来修改下Ghost的配置文件nano config.js更换url: ‘http://my-ghost-blog.com‘, 为你自己的域名.

使用Forever托管Ghost

安装 forever npm install forever -g

运行 Ghost NODE_ENV=production forever start index.js

使用Nginx反向代理Ghost

增加PPA add-apt-repository ppa:nginx/stable

安装Nginx apt-get install nginx-extras

修改Nginx的默认文件nano /etc/nginx/sites-available/default使用以下内容替换server{…}内的所有数据

随后解析你的域名到VPS的ip

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;
}

重启Nginx服务器service nginx restart
然后就可以在浏览器里通过域名访问你的博客了:-D