在Debian 8.7上,如何部署Ghost
杨和超
・8 分钟阅读
使用不同的系统?
Ghost是一个开源博客平台,自2013年发布以来,在开发人员和普通用户中越来越受欢迎,它把焦点放在内容和博客上,Ghost最有吸引力的事情是它的简单,干净和响应性,你可以用手机写你的博客文章,Ghost的内容是使用Markdown语言编写的。
在本指南中,我们将使用let's Encrypt,node.js和Nginx在Debian 8.7 VPS上设置和部署Ghost博客。
let's Encrypt (Certbot )
开始此步骤之前,请确保你已经为你的域设置了DNS记录。
更新系统:
apt update && apt upgrade -y
安装需要的工具:
apt install -y zip build-essential
启用Jessie backports repo ,运行
apt edit-sources
,并且在/etc/apt/sources.list
文件的末尾粘贴下面的行:# Copy/Paste the below line at the end of file deb http://ftp.debian.org/debian jessie-backports main
刷新软件包来源:
apt update
安装Certbot (akaLet's Encrypt客户端):
apt install -y certbot -t jessie-backports
检查版本:
certbot --version # certbot 0.9.3
获取证书:
certbot certonly -d example.com -d www.example.com --email john.doe@mail.com --agree-tos --standalone
经过上述步骤后,你的证书和私钥将在
/etc/letsencrypt/live/example.com
目录中。
安装NodeJS
Ghost目前支持node版本0.12 .x,4.2 +和6.9 +。
我们将安装v4 argon LTS
的推荐版本,这是本文写作时的。
下载并安装它的node.js版本:
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - apt install -y nodejs
检查node和NPM版本:
node -v && npm -v # v4.7.2 # 2.15.11
安装Nginx
下载并安装Nginx :
apt install nginx -t jessie-backports
检查Nginx版本:
nginx -v # nginx version: nginx/1.9.10
启动Nginx服务并检查状态:
systemctl start nginx systemctl status nginx
将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 -t
重新加载Nginx :
systemctl reload nginx
安装Ghost
如果要在同一VPS上托管多个Ghost博客,每个Ghost实例必须在单独的端口上运行。
创建
webroot
目录:mkdir -p/var/www/
创建一个Ghost用户:
adduser ghost
下载并安装Ghost :
cd /var/www wget https://ghost.org/zip/ghost-latest.zip unzip ghost-latest.zip -d ghost chown -R ghost:ghost /var/www/ghost/ rm ghost-latest.zip
切换到
ghost
用户:su -ghost
安装Ghost :
cd /var/www/ghost npm install --production
通过更改
config.js
文件中production
对象的url
属性来配置Ghost :cp config.example.js config.js vi config.js 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
,关于如何做到这一点,请参考官方的Ghost文档。保存
config.js
文件并退出。启动Ghost :
npm start --production
Ghost现在在你的服务器上运行,你可以打开你的浏览器,在
https://example.com
访问你的网站,不要忘记用你的域名替换example.com
。
保持 Ghost 运行
如果关闭你的VPS终端会话,你的博客也将关闭。要避免这个问题,我们将使用Forever进程管理器,这将使您的博客24X7全天候运行。
切换到
ghost
用户:su -ghost
转到
/var/www/ghost
文件夹:cd/var/www/ghost
永久安装:
npm install forever
将新的
forever
命令添加到路径中:echo"export PATH=/var/www/ghost/node_modules/forever/bin:$PATH" >> ~/.bashrc source ~/.bashrc
永远地启动 Ghost :
NODE_ENV=production /var/www/ghost/node_modules/forever/bin/forever start index.js
在这一点上,
forever
应该已经启动了Ghost 。转到
https://example.com/ghost
,并且创建一个Ghost管理员帐户,请尽快执行这个操作。
结束语
就是这样,我们现在有了一个功能完备的 Ghost 博客,如果你想将默认的Casper的主题更改为自定义主题,你可以下载主题,并且解压缩到/var/www/ghost/content/themes文件夹中,然后通过https://example.com/ghost管理界面选择它。