安装 Node.js

  1. yum update -y
  2. yum groupinstall -y "Development Tools"
  3. curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
  4. yum -y install nodejs
  5. npm config set registry https://registry.npm.taobao.org
  6. npm i -g cnpm

安装成功后通过运行 node -vnpm -v 出现版本号即可表示安装成功。

安装 Ghost Client (ghost-cli)

npm i -g ghost-cli

安装成功后通过运行 ghost -v,出现版本号即可表示安装成功。

安装 Ghost

添加 Ghost 运行用户并创建目录

  1. adduser ghost
  2. mkdir /var/www
  3. mkdir /var/www/ghost
  4. chown ghost /var/www/ghost

安装 Ghost

以 SQLite3 作为 Ghost 的数据库。

  1. cd /var/www/ghost
  2. ghost install local --db=sqlite3

基于 CentOS 搭建 Ghost 博客 - 图1
安装成功!

安装 Nginx

添加 Nginx 到 yum 源

使用以下命令添加 CentOS 7 Nginx yum 资源库:

rpm -Uvh [http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm](http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm)

安装 Nginx

yum install -y nginx

基于 CentOS 搭建 Ghost 博客 - 图2
Nginx 完成安装在服务器中

启动 Nginx

刚安装的 Nginx 不会自行启动,需要通过如下命令启动

systemctl start nginx.service

如果一切进展顺利的话,现在你可以通过你 IP( http://<您的 CVM IP 地址>/ )来访问你的 Web 页面来预览一下 Nginx 的默认页面。

基于 CentOS 搭建 Ghost 博客 - 图3

如果看到上面的页面,那么说明你的 CentOS 中的 Nginx 已经正确安装。

另外还可以通过 systemctl enable nginx.service 命令加入开机启动项。

Nginx 配置反向代理

修改 config 文件

请确保 Ghost 已经在运行阶段方可进行如下操作。

vi /etc/nginx/conf.d/default.conf

运行上面的命令后,再键入 i 然后移动光标在约第七行修改相关文件代码:

  1. location / {
  2. root /usr/share/nginx/html;
  3. index index.html index.htm;
  4. }

改为:

  1. location / {
  2. proxy_pass http://127.0.0.1:2368;
  3. proxy_redirect default;
  4. root /usr/share/nginx/html;
  5. index index.html index.htm;
  6. }

完成后通过按 ESC ,随后输入 :wq 回车保存。

基于 CentOS 搭建 Ghost 博客 - 图4

然后重启 Nginx。

  1. nginx -s reload

  1. service nginx restart

扩展阅读:基于 CentOS 搭建 Ghost 博客