在使用 Ghost 官方安装工具 Ghost-CLI 时,老搭建错误,所以这里把 Ghost 作为 npm module 来安装。
安装 Passenger
apt-get install -y dirmngr gnupg lsb-release apt-transport-https ca-certificates unzip git wget curl sudo sqlite3 && apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 && sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger $(lsb_release -sc) main > /etc/apt/sources.list.d/passenger.list' && apt-get update && apt-get install -y passenger
以 npm 形式安装 Ghost
curl -sL https://deb.nodesource.com/setup_8.x | bash - && curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list && apt update && apt install nodejs yarn -y
mkdir -p /var/www/ghost && cd /var/www/ghost
yarn init
yarn add ghost@latest --save
cp -r node_modules/ghost/content .
创建启动文件 index.js
cat > /var/www/ghost/index.js << EOF
const ghost = require('ghost');
ghost().then(function (ghostServer) {
return ghostServer.start();
})
EOF
创建配置文件 config.production.json
参考配置文件如下,记得修改 "contentPath": "content" 这一项
{
"url": "https://example.com",
"database": {
"client": "sqlite3",
"connection": {
"filename": "content/data/ghost.db"
},
"debug": false
},
"paths": {
"contentPath": "content"
},
"useMinFiles": true,
"logging": {
"level": "info",
"rotation": {
"enabled": true
},
"transports": ["file", "stdout"]
}
}
启动 Ghost
NODE_ENV=production node index.js
这样就可以完成数据库初始化到操作,然后我们使用 passenger 来启动 Ghost
passenger start --app-type node --startup-file index.js --address 127.0.0.1 --port 2368 --environment production --daemonize
如果需要停止则执行:
passenger stop -p 2368
Nginx 配置
vim /etc/nginx/conf.d/ghost.conf
server {
listen 443 ssl http2;
server_name example.com;
keepalive_timeout 300;
ssl_certificate_key /etc/ssl/example.com.key;
ssl_certificate /etc/ssl/example.com.crt;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 24h;
ssl_buffer_size 1400;
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains';
location / {
proxy_hide_header X-powered-by;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
重启 Nginx,打开 https://example.com/ghost/ 结束安装
nginx -t
service nginx restart
本文参考至 1