首页 技术 正文
技术 2022年11月6日
0 收藏 911 点赞 492 浏览 2780 个字

Ghost 是一款使用 Node.js 开发的博客系统,相对于使用 PHP 开发的 WordPress 更轻巧友好,所以本站已经从 WordPress 切换至 Ghost,本文介绍在 Debian 8.x 和 Ubuntu 16.04 下搭建 Ghost 的教程

本文所有操作均在 root 用户下进行,请自行切换

首先,更新系统

apt-get update && apt-get upgrade

如果您用的 Debian 8.x 开启了 backports 也可以更新下

apt-get -t jessie-backports update && apt-get -t jessie-backports upgrade

1、安装 Node.js 6.x LTS

由于系统自带的 Node.js 较老,这里我们采用 NodeSource 编译的 Node.js 源

Ubuntu 下

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

Debian 下

curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install nodejs

2、安装 Nginx

Ubuntu 下可以用 PPA

Debian 下可以用 Dotdeb

然后安装 Nginx 以及一些必要的软件

apt-get install nginx unzip wget curl sudo sqlite3

3、下载 Ghost

这里我们演示把 Ghost 下载并解压在 /var/www/ghost 目录

cd /var/www/ && wget https://ghost.org/zip/ghost-latest.zip && unzip ghost-latest.zip -d ghost && rm -rf ghost-latest.zip

4、添加 ghost 用户并修改权限

useradd ghost
chown -R ghost:ghost /var/www/ghost

5、修改 config.js

cd /var/www/ghost
cp -r config.example.js config.js

接着就可以修改 config.js 按照实际情况,修改 config 段,举例如下

config = {
// ### Production
// When running Ghost in the wild, use the production environment.
// Configure your URL and mail settings here
production: {
url: 'http://example.com', //修改为你博客的域名,如需要启动 SSL 则改为 https
mail: {},
database: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/content/data/ghost.db')
},
debug: false
}, server: {
host: '127.0.0.1',
port: '2368'
}
},

如果需要后台发送邮件给用户,您可以配置 mail 参数,例如:

mail: {
transport: 'SMTP',
options: {
service: 'Mailgun',
auth: {
user: '', // mailgun username
pass: '' // mailgun password
}
}
},

Ghost 用的是 Nodemailer,如果您需要其他服务商的 service 名字,可以在官网文档里查看。

6、安装并启动 Ghost

cd /var/www/ghost
npm install --production
npm start --production

如果在 Ubuntu 16.04 下提示

Error: Cannot find module '/var/www/ghost/node_modules/sqlite3/lib/binding/node-v48-linux-x64/node_sqlite3.node'

则需要安装 nodejs 的 sqlite3

npm install sqlite3 --save

可以在本机上打开 http://127.0.0.1:2368/ 查看在线版本

7、配置 Nginx

按 ctrl + c 停止 Ghost ,然后我们可以修改 Nginx 配置文件,举例如下

server {
listen 80;
listen [::]:80; server_name example.com; location / {
proxy_pass http://127.0.0.1:2368;
proxy_redirect default;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 10m;
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_hide_header X-Powered-By;
}
}

检查并重新加载 nginx

nginx -t
nginx -s reload

8、安装 PM2 使 Ghost 保持后台运行

PM2 是一款很流行的 Node.js 进程管理器,可以做到开机启动和重新关闭等操作

首先我们通过 npm 安装 PM2

cd /var/www/ghost
npm install pm2 -g

配置当前环境,并设置开启启动,然后保存

NODE_ENV=production pm2 start index.js --name ghost
pm2 startup
pm2 save

后续可能需要用到的命令有

启动 Ghost

pm2 start ghost

停止 Ghost

pm2 stop ghost

重启 Ghost

一般用于修改了主题文件或进程隔屁的情况

pm2 restart ghost

好了,大功告成,打开浏览器访问 http://example.com/ghost/ 注册的第一个账号就是全站管理员,接着就可以开始 Ghost 的博客之旅了

扩展阅读

观赏鱼品种大全

鹿角苔需要怎么养

水族有趣见闻

国内最有意思的水族观赏鱼论坛

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,030
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,859