Debian 8.x / Ubuntu 16.04.x 搭建 Ghost 教程
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 的博客之旅了
擴展閱讀
觀賞魚品種大全
鹿角苔需要怎麽養
水族有趣見聞
國內最有意思的水族觀賞魚論壇
Debian 8.x / Ubuntu 16.04.x 搭建 Ghost 教程