这里我们介绍下在 Ubuntu 14.04 LTS 安装 Node.js 和 Ghost 的方法。
一、安装 Node.js
为了保持最新版本,我们采用 PPA 形式,可以直接用这个脚本导入 PPA:
sudo curl -sL https://deb.nodesource.com/setup | sudo bash -
导入完毕以后,直接安装 Node.js
sudo apt-get install nodejs
这个 Node.js 的包已经包含了 npm 所以你不用单独安装 npm,而有些 Node.js 程序还得单独安装 build-essentials 包,你也可以安装一下:
sudo apt-get install build-essential
安装完毕以后查看一下 Node.js 和 npm 的版本
root@example:~# node -v
v0.10.33
root@example:~# npm -v
1.4.28
Ghost 需要运行在 0.10.* 的 Node.js 版本,请注意。
二、下载 Ghost 程序
基于安全考虑,可以新建立个 ghost 用户,这里我们安装在 /var/www/ 目录下
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
这样就设置好权限并下载好 Ghost 了
三、安装配置 Ghost
首先用 npm 安装
npm install --production
注意有两个减号
npm 安装结束后,可以输入这个命令让 Ghost 以开发者模式启动
npm start
然后就可以本机从 http://127.0.0.1:2368/ 查看搭建好的 Ghost 博客了,由于我们是安装在服务器端,所以你本地浏览器是无法访问的,先按 Ctrl + C 停止一下,这时候就会生成一个 config.js,然后修改 config.js
把 url: 'http://my-ghost-blog.com', 这行改成你的域名,比如 url: 'http://example.com',
安装结束,然后我们需要让 Ghost 保持后台运行,并配置 Nginx 反向代理让外网可以访问。
四、让 Ghost 保持后台运行 + 开启启动
这里有两种方式
1、使用 forever 以后台任务运行 Ghost
安装 forever
npm install forever -g
运行 Ghost
NODE_ENV=production forever start index.js
然后可以通过 forever stop index.js 停止 Ghost
也可以通过 forever list 检查 Ghost 是否运行
2、使用 Supervisor 后台运行 Ghost 并开机启动
安装 Supervisor
sudo apt-get install supervisor
创建一个 Ghost 启动脚本文件,如 /etc/supervisor/conf.d/ghost.conf 编辑如下
[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"
重启 Supervisor 即可生效
service supervisor restart
也可以使用 Supervisor 启动 Ghost
supervisorctl start ghost
然后我们开始安装 Nginx 配置反向代理让你本地可以访问。
四、安装 Nginx 配置反向代理
首先安装 Nginx
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx-extras
修改 /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;
}
}
保存并重启 Nginx
sudo service nginx restart
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔