最近准备在一个项目中使用一个轻量级的博客做项目的公开文档平台,项目文档本身是用markdown格式写的,因此使用Ghost就是顺理成章的了。花了一个小时在项目服务器(阿里云ECS,操作系统CentOS 7.2 64位)上完成了初始安装,步骤如下:
- 登录到服务器,更新软件,确认wget,unzip,node,npm这些软件都有
- 下载最新版Ghost
1
| wget https://ghost.org/zip/ghost-latest.zip
|
- 创建准备安装Ghost的目录,zip压缩包解压缩到这里
1
| mkdir /yourGhostPath/ghostunzip -d /yourGhostPath/ghost ghost-latest.zip
|
- 安装Ghost
1
| cd /yourGhostPath/ghostnpm install --production
|
- 配置Ghost
1
| cp config.example.js config.jsvi config.js
|
将配置文件中production: {下面一行
1
| url: 'http://your_domain_or_ip_address',
|
单引号中的网址替换为你打算设置的网址,保存config.js文件退出
6. 配置Nginx
1
| cd /yourNginxPath/nginx/mkdir sites-availablemkdir sites-enabledvi /yourNginxPath/nginx/sites-available/ghost
|
写入以下内容
1
| server {listen 80;server_name your_domain_or_ip;location / { proxy_set_header HOST $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:2368; }}
|
注意,以上代码第三行的your_domain_or_ip请替换为你准备使用的域名或公网IP地址
1
| ln -s /yourNginxPath/nginx/sites-available/ghost /yourNginxPath/nginx/sites-enabled/ghostvi /yourNginxPath/nginx/conf/nginx.conf
|
在http代码块内,加入
1
| include /yourNginxPath/nginx/sites-enabled/*;
|
后保存退出
重启nginx
7. 创建一个新用户来执行ghost
1. 创建新用户:
{% codeblock lang:bash %}
adduser ghost
{% endcodeblock %}
2. 设置密码:
{% codeblock lang:bash %}
passwd ghost
{% endcodeblock %}
3. 加入sudoer:
{% codeblock lang:bash %}
usermod -aG wheel ghost
{% endcodeblock %}
4. 更改ghost目录用户:
{% codeblock lang:bash %}
chown -R ghost:ghost /yourGhostPath/ghost/
{% endcodeblock %}
使用pm2启动ghost服务
- 使用ghost用户
- 安装pm2
1
| cd /yourGhostPath/ghostsudo npm install -g pm2echo "export NODE_ENV=production" >> /yourGhostPath/.profilesource /yourGhostPath/.profilepm2 killpm2 start index.js --name ghostpm2 dumpsudo pm2 startup centos
|
- 常用的pm2命令
查看状态:pm2 status
停止服务:pm2 stop ghost
查看日志:pm2 logs