采用 Ghost-CLI 来快捷安装 Ghost 博客

大于 1G 内存的 VPS, Debian 8, root 用户登录
若你的是 KVM 虚化的小内存 VPS,你可以设置 Swap 来运行博客,参考此篇文章

准备

apt-get update && apt-get install vim git curl wget build-essential -y

安装 Node.js

curl -sL https://deb.nodesource.com/setup_6.x | bash -
apt-get install -y nodejs
npm i -g yarn

安装 Nginx

wget http://nginx.org/keys/nginx_signing.key && apt-key add nginx_signing.key && rm nginx_signing.key && echo "deb http://nginx.org/packages/mainline/ubuntu/ xenial nginx" >> /etc/apt/sources.list.d/nginx.list && echo "deb-src http://nginx.org/packages/mainline/ubuntu/ xenial nginx  " >> /etc/apt/sources.list.d/nginx.list && echo "deb http://httpredir.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/backports.list && echo "deb-src http://httpredir.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list.d/backports.list && apt-get update && apt-get install -t jessie-backports openssl -y && apt-get install -y nginx

安装 Mysql

wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb && dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb && rm dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb && apt-get update && apt-get install percona-server-server-5.7 -y

进行安全设置

mysql_secure_installation  

登录 Mysql

mysql -u root -p  

输入 Root 密码,进入 Mysql 控制台,创建数据库

CREATE DATABASE ghost DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;  

创建 Mysql 用户

GRANT ALL ON ghost.* TO 'ghost'@'localhost' IDENTIFIED BY '这里改成你要设置的强大的没人能猜出来的随机的密码';  

安装 Ghost

先安装 Ghost-CLI

npm i -g ghost-cli

安装最新版本 Ghost

mkdir /home/ghost && cd /home/ghost && ghost install

接下来会要求你输入域名、数据库账号密码

ghost start

Ghost 就启动成功了,看一眼运行端口

cat config.production.json

里面的 127.0.0.1: 后面的即为运行端口

Nginx 配置文件

vim /etc/nginx/conf.d/ghost.conf

i 进入编辑模式,粘贴下方内容:

server {
    listen 80;
    server_name example.com; #改成你自己的域名
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com; #改成你自己的域名

    #改成你自己域名的证书,签发教程可以看这 https://yjk.im/le-ecc-ssl/
    ssl_certificate /root/.acme.sh/example.com/fullchain.cer;
    ssl_certificate_key /root/.acme.sh/example.com/example.com.key;

    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers  on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    location / {
        sub_filter 'http://example.com' 'https://example.com'; #改成你自己的域名
        sub_filter_once off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Accept-Encoding "";
        proxy_pass http://127.0.0.1:2368; #记得把端口改成上方查看到的端口
        proxy_redirect off;
    }
}

然后重启 Nginx

service nginx restart

将你的域名指向 VPS 的 IP

就大功告成,访问你的域名 (example.com/ghost) 开始注册博客管理账号

升级 Ghost

  • 升级 Ghost-cli npm i -g ghost-cli
  • 升级 Ghost cd /home/ghost && ghost update

  2017-09-05     Ghost, Ghost博客, VPS     返回顶部