ubuntu 14.04 ghost 搭建

ghost是一个精简的博客系统,而wordpress这么久已经不只博客了,所以略感臃肿。 中文官方文档介绍的也挺详细的,我来做个搬运工。

主要步骤就以下几条:

1.安装Node.js
2.下载ghost和配置ghost
3.使ghost永久运行
4.安装Nginx配置反向代理

当然你需要服务器解析好了的域名,默认root用户。

一. 安装nodejs

官方推荐node为4.2-5.*,所以不要轻易装最新node:

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

使用node -v && npm -v 查看当前安装版本。

二. 安装配置ghost

如果没有安装unzip,那就apt-get安装一下,

mkdir /var/www/ghost
cd /var/www/ghost
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip ghost.zip

下一步npm安装ghost依赖,注意是两个' - ',然后编辑配置文件

npm install --production
cp config.example.js config.js
vim config.js

把 url: '//my-ghost-blog.com', 改成自己的域名

使用 npm start --production 就可以运行了, ctrl+c结束。

三. 使ghost后台和开机运行

使用 forever 以后台任务运行 Ghost

npm install forever -g
NODE_ENV=production forever start index.js

使用forever stop/strat index.js可以停止/启动ghost,
使用 forever list可以查看运行状态。

四. 安装 Nginx 配置反向代理

apt-get直接安装 nginx

apt-get install nginx

配置nginx的反向代理

vim /etc/nginx/sites-available/ghost.conf

写入如下配置,把 example.com 改成你自己的域名

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:2368;
    }
}

再把这个配置文件连接到sites-enabled中

ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf

不出意外的话重启nignx就可以了

service nginx restart

打开浏览器输入 域名/ghost/ 就可以使用ghost了。