起因

由于几年前用的ubuntu16.04基本都要停止更新了,而且本源里面有很多的软件版本比较落后。
加之在VPS上更新到18.04和20.04都或多或少有问题,所以这次直接备份重装debian11,再部署一次。

之前我写过用一键脚本直接安装ghost,但是迫于很多的内容都比较不完美。而且新的版本更新总是会带来或多或少的问题。ghost的大版本更新真滴很伤脑筋。第一是担心主题的兼容性。第二是后台的数据库直接导出不太友好。第三是ghost本身如果通过ghost-cli安装会需要non-root用户才行,对于我来说有点麻烦了。能直接root运行docker跑起来其实真滴算是很方便的事情。

所以目前总结来就是以下几个步骤:

步骤

1、安装docker
curl -sSL https://get.docker.com/ | sh
2、安装ghost on docker
docker run --name ghost -p 127.0.0.1:2368:2368 -e url=https://xratzh.com -v /var/www/ghost/content:/var/lib/ghost/content --restart=always -d ghost
这里可以直接指定ghost版本,后缀可以:版本号解决。后面的数据备份对于这些版本都可以用的。
3、配置nginx

  • 安装nginx

  • /etc/nginx/sites-available/ghost.conf文件进行编辑,我是自签的cloudclare的ssl证书放到/etc/SSL目录下面的,我贴一个我的配置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    server {
    listen 80;
    server_name xratzh.com;
    server_tokens off;

    location / {
    return 301 https://$server_name$request_uri;
    }
    }
    server {
    server_name zmoe.me;
    listen 443 ssl;
    server_tokens off;

    location / {
    proxy_pass http://localhost:2368;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    ssl_certificate /etc/SSL/fullchain.pem;
    ssl_certificate_key /etc/SSL/privkey.pem;
    }
  • ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf把编辑的文件设为启用

  • service nginx restart重启就生效了

4、ghost数据还原:

  • 其实最开始使用的是后台的导出功能,但是导入到最新的4.X版本,总是会报错。多次重装、换版本都无果
  • 后满直接打包原来的ghost文件夹,重装后上传,然后解压到docker指定的ghost数据地址。安装后会自动调用原有的数据,这个其实最完美最方便。

5、顺便备份打包github.io的数据库到新的服务器上(因为20年github取消了直接用密码认证上传的方式)

转载请注明出处:https://xratzh.com/2022/02/04/ghost-on-docker