如何在Fedora 25上部署Ghost
Yanyan
・8 分钟阅读
要求
- Fedora 25服务器实例,最小内存为1GB,,
- 你可能需要打开端口2368
semanage port -a -t http_port_t -p tcp 2368
,
let's Encrypt
开始此步骤之前,请确保你已经为你的域设置了DNS记录。
我们将使用let'sEncrypt CA和EFF的Certbot客户端来获取Ghost博客的TLS证书,不要忘记用你的域名替换example.com
的所有实例。
更新系统:
dnf check-update || dnf upgrade -y
安装需要的工具:
dnf install @development-tools -y
安装Certbot a,k。a让我们加密客户端
dnf install certbot -y
检查Certbot版本:
certbot --version # certbot 0.12.0
使用standalone的模式获取证书:
certbot certonly --standalone --domains example.com,www.example.com --email john.doe@example.com --agree-tos --rsa-key-size 2048
经过上述步骤后,你的证书和私钥会在/etc/letsencrypt/live/example.com
目录中。
安装NodeJS
我们将安装受支持的v6 Boron LTS
版本,这是本文写作时的。
下载并安装最新版本的node.js :
dnf install nodejs -y
检查node和NPM版本:
node -v && npm -v # v6.10.2 # 3.10.10
安装Nginx
下载并安装Nginx :
dnf install nginx -y
检查Nginx版本:
nginx -v # nginx version: nginx/1.10.2
启动并启用Nginx服务:
systemctl start nginx.service && systemctl enable nginx.service
将Nginx配置为反向代理:
vi /etc/nginx/conf.d/ghost.conf
在
/etc/nginx/conf.d/ghost.conf
中粘贴以下内容:server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.com www.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://127.0.0.1:2368; } }
检查Nginx语法:
nginx -t
重新加载Nginx配置:
systemctl reload nginx.service
安装Ghost
如果要在同一VPS上托管多个Ghost博客,每个Ghost实例必须在单独的端口上运行。
创建
webroot
目录:mkdir -p/var/www/
创建一个新的ghost用户:
useradd -c"Ghost Application" ghost
下载Ghost :
curl -L https://github.com/TryGhost/Ghost/releases/download/0.11.8/Ghost-0.11.8.zip -o ghost.zip
解压Ghost:
unzip -uo ghost.zip -d /var/www/ghost rm -f ghost.zip
导航到webroot :
cd/var/www/ghost
更改webroot目录的所有权:
chown -R ghost:ghost .
切换到新的ghost用户:
su -ghost
导航到webroot :
cd/var/www/ghost
安装Ghost :
npm install --production
通过在
config.js
文件中更改production
对象的url
和mail
属性来配置Ghost :cp config.example.js config.js vi config.js var path = require('path'), config; config = { // ### Production // When running Ghost in the wild, use the production environment. // Configure your URL and mail settings here production: { url: 'https://example.com', mail: { options: { service: '', auth: { user: '', pass: '' } } }, . . . . . . }, } . . . . . .
注:你还应该配置
mail
,有关如何执行此操作,请参阅Ghost官方文档。启动Ghost :
npm start --production
Ghost将立即运行,博客前端和管理界面都是通过HTTPS 和HTTP/2 进行保护,你可以打开你的浏览器,并且在
https://example.com
访问网站,不要忘记用你的域名替换example.com
。按
CTRL
+C
关闭Ghost进程,然后从Ghost用户退出到root用户:exit
安装PM2
如果你关闭与VPS的终端会话,你的博客也会关闭。这不好,要避免这个问题,我们将使用PM2流程管理器。 它将保持我们的博客24/7全天候运行。
安装PM2进程管理器的最新稳定版本:
npm install -g pm2@latest
检查PM2版本:
pm2 -v # 2.4.6
再次切换到ghost用户:
su -ghost
将
NODE_ENV
环境变量设置为生产:echo"export NODE_ENV=production" >> ~/.bashrc && source ~/.bashrc
使用PM2启动(守护进程)Ghost应用程序:
pm2 start /var/www/ghost/index.js --name"Ghost Blog"
导航到
https://example.com/ghost/
,并且创建Ghost管理员用户,请尽快执行这个操作。
结束语
就是这样我们现在有了一个功能完备的幽灵博客。