部署 - 托管方案
准备
- 域名一个(非必须)
- 可以支付外币的支付方式
云托管服务商选择
它不可以像静态博客一样使用 Vercel/Railway/Netfily 这类云平台托管,以下列出了一些支持的云平台。
- Ghost (PRO)
- Digital Ocean
- Google Cloud
- PikaPods
…
关于托管的详细的搭建步骤,等我有空更新。我们先把重点放到自托管方案。
部署 - 自托管方案
准备
- 至少有 1GB 内存的服务器一台(荐使用全新的系统环境操作)
- 域名一个,并且已经提前设置一个有效的 DNS A 记录,指向服务器的 IP 地址。必须提前完成此操作
- SSH工具,例如 Xshell、FinalShell、Termius 等
开始部署
如果你对 Docker相关命令已经了解,那么我推荐你使用 Docker 安装。缺点是如果你想在容器内使用现代化的编辑器来编辑文件会比较麻烦,最方便的是vim 等命令进行编辑、添加文件的操作。
如果你直接在服务器上搭建,就可以避免这个问题。我们可以非常方便的使用VScode 编辑文件内容。使用Termius的SFTP功能直接添加\删除文件。
我将基于官方推荐的搭载了 Ubuntu 20.04 LTS 系统的服务器开始教程。
本教程将确保满足安装 Ghost-CLI 的所有先决条件。
1. 更新软件包
sudo apt update && apt upgrade -y
2.创建新用户
注意:用户名使用ghost会导致与Ghost-CLI冲突,你可以使用除ghost 以外的任何名称
- 创建一个新用户,用户名需自行替换
adduser
New password:
# 看到这个提示后,输入你想设置的密码。这里要注意,输入的密码是隐藏 不可见的,输入完毕后回车即可
Retype new password:
# 重新输入上一步的密码
Enter the new value, or press ENTER for the default
# 这里按回车默认
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
# 这里确认信息输入正确后输入 y 并按下回车
- 为新增用户添加 sudo 权限
usermod -aG sudo
# 将替换成你最开始设置的用户名
su -
# 切换到这个用户
完整操作示例:
root@ns348668:~# adduser hosteye
Adding user `hosteye' ...
Adding new group `hosteye' (1001) ...
Adding new user `hosteye' (1001) with group `hosteye' ...
Creating home directory `/home/hosteye' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for hosteye
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root@ns348668:~# usermod -aG sudo hosteye
root@ns348668:~# su - hosteye
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.
3.安装NGINX
Ghost 使用 NGINX 服务器,SSL 配置需要 NGINX 1.9.5 或更高版本。
# 安装nginx
sudo apt-get install nginx
如果ufw激活,防火墙应允许 HTTP 和 HTTPS 连接。
# 检查防火墙是否开启
sudo ufw status
# 如果防火墙开启,输入此命令允许 HTTP 和 HTTPS 连接。
sudo ufw allow 'Nginx Full'
Rules updated
Rules updated (v6)
# 开启成功后会输出此信息
4.安装MySQL
# 安装MySQL
sudo apt-get install mysql-server
# 进入mysql
sudo mysql
# 重置mysql root 密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
# 退出mysql
quit;
5.安装Node.js

注意 Ghost 仅支持Node.js 16.x、18.x 两个大版本(推荐安装Node 18.x)
我这里选择安装18.x。
# 从 NodeSource 添加 Node.js 18 下载源
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash
# 安装 Node.js
sudo apt-get install -y nodejs
6.安装 Ghost-CLI
Ghost-CLI是一个命令行工具,可帮助您快速、轻松地安装和配置 Ghost 以供使用。可以使用npm或yarn安装。
# 使用npm安装 Ghost-CLI
sudo npm install ghost-cli@latest -g
# 如果出现以下提示,这是 npm 存在新版本可升级的提示。这里可以自行选择是否需要升级。
npm notice
npm notice New minor version of npm available! 9.6.7 -> 9.8.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.8.1
npm notice Run npm install -g [email protected] to update!
npm notice
7.安装Ghost
一旦你的服务器正确设置并且ghost-cli安装完毕,就可以安装 Ghost 了。以下步骤是推荐的设置。如果您需要更精细的控制,请参考Ghost-CLI
# 创建目录: 将 `sitename` 更改为站点名,或其他
sudo mkdir -p /var/www/sitename
# 设置目录所有者: 将 替换为一开始设置的用户名。 !注意区分站点名和用户名
sudo chown : /var/www/sitename
# 设置正确的权限
sudo chmod 775 /var/www/sitename
# 然后进入
cd /var/www/sitename
现在我们用最后一个命令行安装 Ghost。
ghost install
# 以下是安装示例,请参考。
hosteye@ns348668:/var/www/hosteye$ ghost install
Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org
# 检查系统环境
✔ Checking system Node.js version - found v18.17.0
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking free space
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v5.55.1
✔ Finishing install process
# 输入你希望绑定的确切 URL,包括 HTTP 或 HTTPS 协议。例如,https://example.com. 如果使用 HTTPS,Ghost-CLI 将会设置 SSL。使用 IP 地址会导致错误。
? Enter your blog URL: https://hosteye.net
# 输入MySQL主机名。如果MySQL安装在其他服务器上,请手动输入对应主机名。
? Enter your MySQL hostname: localhost
# 输入 root ,然后输入 root 用户的密码。如果你已经有一个 MySQL 数据库,请输入对应的用户名和密码。
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
# 如果还没有创建过数据库,可以直接使用默认值: db_ghost 或者输入想要设置的数据库名。随后系统会开始自动设置。如果在上一步中使用的是非 root 的 MySQL用户名/密码,需要确保该数据库已经存在,并且具有正确的权限。
? Enter your Ghost database name: db_hosteye
✔ Configuring Ghost
✔ Setting up instance
sudo useradd --system --user-group ghost
sudo chown -R ghost:ghost /var/www/hosteye/content
✔ Setting up "ghost" system user
# 如果在此前提供了 root MySQL 用户,Ghost-CLI 可以自动创建一个属于 Ghost 数据库的自定义 MySQL 用户,该用户只能访问/编辑新的 Ghost 数据库,而不能执行其他操作。
# 输入y确定创建
? Do you wish to set up "ghost" mysql user? Yes
✔ Setting up "ghost" mysql user
# 自动设置NGINX
? Do you wish to set up Nginx? Yes
sudo mv /tmp/hosteye-net/hosteye.net.conf /etc/nginx/sites-available/hosteye.net.conf
sudo ln -sf /etc/nginx/sites-available/hosteye.net.conf /etc/nginx/sites-enabled/hosteye.net.conf
sudo nginx -s reload
✔ Setting up Nginx
# 自动设置SSL。要注意在第一步要输入带 https 的地址作为URL,并且正确配置了记录
? Do you wish to set up SSL? Yes
# SSL 认证设置需要一个电子邮件地址,以便你可以在证书出现任何问题(包括续订期间)时收到通知。
? Enter your email (For SSL Certificate) [email protected]
sudo mkdir -p /etc/letsencrypt
sudo ./acme.sh --install --home /etc/letsencrypt
sudo /etc/letsencrypt/acme.sh --issue --home /etc/letsencrypt --server letsencrypt --domain hosteye.net --webroot /var/www/hosteye/system/nginx-root --reloadcmd "nginx -s reload" --accountemail [email protected] --keylength 2048
sudo openssl dhparam -dsaparam -out /etc/nginx/snippets/dhparam.pem 2048
sudo mv /tmp/ssl-params.conf /etc/nginx/snippets/ssl-params.conf
sudo mv /tmp/hosteye-net/hosteye.net-ssl.conf /etc/nginx/sites-available/hosteye.net-ssl.conf
sudo ln -sf /etc/nginx/sites-available/hosteye.net-ssl.conf /etc/nginx/sites-enabled/hosteye.net-ssl.conf
sudo nginx -s reload
✔ Setting up SSL
# systemd是推荐的进程管理器工具,以保持 Ghost 顺利运行。建议选择yes。但也可以设置自己的流程管理。
? Do you wish to set up Systemd? Yes
sudo mv /tmp/hosteye-net/ghost_hosteye-net.service /lib/systemd/system/ghost_hosteye-net.service
sudo systemctl daemon-reload
✔ Setting up Systemd
sudo systemctl is-active ghost_hosteye-net
# 确定启动Ghost
? Do you want to start Ghost? Yes
sudo systemctl start ghost_hosteye-net
sudo systemctl is-enabled ghost_hosteye-net
sudo systemctl enable ghost_hosteye-net --quiet
✔ Starting Ghost
Ghost uses direct mail by default. To set up an alternative email method read our docs at https://ghost.org/docs/config/#mail
------------------------------------------------------------------------------
# Ghost安装完成
Ghost was installed successfully! To complete setup of your publication, visit:
https://example/ghost/
8.如果安装失败怎么办
如果安装出现严重错误,请使用ghost uninstall将其删除并重试。这比删除文件夹更可取,以确保不留下任何痕迹。
如果安装中断或连接丢失,请用于ghost setup重新启动配置过程。
对于故障排除和错误,请使用站点搜索和常见问题解答部分来查找有关常见错误消息的信息。

简单美化、后台功能介绍、评论功能、会员功能、代码高亮、路由、RSS、性能优化、自定义主题……等教程,等我慢慢更新。
今天先这样吧~
好帖 绑定
有图就更好了 绑定一下