MENU

#教程#Ubuntu16.04搭建Ghost博客系统V1.0/1.x

August 5, 2017 • Read: 7129 • 网络笔记

关于Ghost博客的搭建我在之前也有过介绍,这种搭建主要针对于习惯中文版的用户,因为Ghost1.0出来以后还没来得及发布中文版,而目前的中文版定在了Ghost0.74,如果你需要使用中文版,请转移到此处

VPS配置

  • 本次搭建使用的VPS是 Vultr日本
  • 镜像使用:Ubuntu 16.04 × 64位

环境配置

此次搭建需要配置Nginx Mysql Ghost-cli Node.js

更新系统

apt-get update && apt-get upgrade

安装node.js

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -  
apt-get install nodejs  

安装Nginx

Ubuntu 16.04 推荐使用 Ondřej Surý 制作的 PPA

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/nginx-mainline
sudo apt-get update

然后直接安装:sudo apt-get install nginx

安装Mysql

sudo apt-get install mysql-server

新建用户

为了在安装Ghost install的过程中出现不必要的错误,所以我们需要为Ghost install 新建立一个用户

adduser ghost

然后系统会提示你输入两次密码,其他的一律回车即可

接着给予 ghost 用户 sudo 权限,这样这货就可以执行好多操作了

usermod -aG sudo ghost

使用新建用户

su - ghost

输入密码后即可配置

新建文件夹

首先你需要先回到你的root账户中,假设你的博客要放在 /var/www/ghost 目录,那么我们就创建一个并赋予权限

sudo mkdir /var/www/ghost
sudo chown ghost:ghost /var/www/ghost

其中的前面加粗的ghost是你新建的用户,你需要赋予新建用户使用权限

安装 Ghost-CLI

使用你新建用户 su - ghost

sudo npm i -g ghost-cli

安装Ghost

进入你刚所创文件夹

cd /var/www/ghost
ghost install

即可安装

配置Nginx

这是最后一步,也是最重要的一步

让我们先回到root用户

编辑一个网站conf配置
例如:

vi /etc/nginx/sites-enabled/example.com.conf

案例Nginx配置

这是我的Nginx配置,使用时需要将网站跟端口修改成你们自己的

server
{
    listen 80;
    server_name eason.fun;(你的域名)
    root /var/www/eason.fun;(Ghost所在目录)
    
    
    location / {
client_max_body_size 35m; 
proxy_set_header Host $http_host; 
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:2370;(你的端口)

      }

 }

重启Nginx

sudo nginx -t && sudo nginx -s reload

遇到的问题

Ghost博客在后期的更新中禁止了使用root用户,所以我们还要在之前创造的Ghost用户上再次赋予权限

chown [-R] 你所创的用户 你Ghost所安装的目录

在后来版本中 Ghost用户将不被允许!

升级Ghost博客

更新 Ghost-CLI

进入 Ghost 安装目录,查看 Ghost-CLI 和当前目录安装的 Ghost 版本:

ghost -v
Ghost-CLI version: 1.1.3
Ghost Version (at /home/wwwroot/ghost): 1.16.0

如出现以下提示,则 Ghost-CLI 有新版本:

 ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 1.1.3 → 1.2.0    │
   │    Run npm i ghost-cli to update    │
   │                                     │
   ╰─────────────────────────────────────╯

更新 Ghost-CLI:

# yarn
yarn global add ghost-cli
# npm
npm install -g ghost-cli
使用 Ghost-CLI 更新 Ghost

在 Ghost 安装目录,执行:

ghost update

Process manager 'systemd' will not run on this system, defaulting to 'local'
✔ Checking for latest Ghost version
✔ Downloading and updating Ghost to v1.17.0
ℹ Stopping Ghost [skipped]
✔ Linking latest Ghost and recording versions
Running sudo command: /usr/local/share/.config/yarn/global/node_modules/ghost-cli/node_modules/.bin/knex-migrator-migrate --init --mgpath /home/wwwroot/ghost/current
✔ Running database migrations
✖ Validating config
✖ Restarting Ghost
A ConfigError occurred.

Error detected in the production configuration.

Message: Port '2368' is in use.
Configuration Key(s): server.port
Current Value(s): 2368

Help: Run ghost config <key> <new value> for each key to fix the issue.

Debug Information:

Node Version: v6.11.5
Ghost-CLI Version: 1.2.0
Environment: production
Command: 'ghost update'

Please refer to https://docs.ghost.org/v1/docs/troubleshooting#section-cli-errors for troubleshooting.
看到 ✔ Downloading and updating Ghost to v1.17.0 和 ✔ Linking latest Ghost and recording versions 表示更新已下载并安装成功,出错是因为未检测到 systemd ,此时需要我们手动重启 ghost 服务即可。

在 Ghost 安装目录,查看之前使用 Ghost-CLI 生成的服务文件:

ls ./system/files/
ghost_undefined.service

使用 systemd 重启 Ghost 服务:

systemctl restart ghost_undefined.service
Last Modified: October 19, 2018
Archives QR Code Tip
QR Code for this page
Tipping QR Code
Leave a Comment

7 Comments
  1. @(呵呵) 你这明明是te哪里是Ghost。主题真好看。我在用Ghost 1.5,很不错啊

    1. @Desertste是啥?

    2. @Deserts哦哦哦 我用的是tyepcho做主博客,但是平时写点记录什么的用Ghost比较多

  2. 博主我似乎出了问题,想问下你问题不知道有没有联系方式?

  3. XX XX

    文章有误导,不可使用ghost用户。

    1. @XX不可使用root用户而非Ghost用户

  4. [...]如果你要搭建Ghost博客,请点击此处[...]