在 Debian 和 Ubuntu 上安装 Ghost (CMS) 博客发布平台
Ghost 是一个免费、开源、轻量级的平台,旨在用于博客或在线出版物。它是用 Nodejs 编写的,并附带了各种现代发布工具,旨在轻松构建和运行在线出版物。
它功能丰富,现在有一个桌面应用程序(在 Linux、Windows 和 Mac OS 上运行),只需在您的计算机上即可提供 Ghost 的所有功能和强大功能。这意味着您可以随时随地轻松地在多个站点之间切换:使其绝对高效。
幽灵特点:
- 快速、可扩展且高效。
- 提供基于 Markdown 的编辑环境。
- 附带桌面应用程序。
- 配有漂亮的车把模板。
- 支持简单的内容管理。
- 支持作者、编辑和管理员的多重角色。
- 允许提前安排内容。
- 支持加速移动页面。
- 全面支持搜索引擎优化。
- 提供详细的结构化数据。
- 支持RSS、Email、Slack订阅。
- 实现简单的站点编辑等等。
要求:
- 具有 1GB 内存的 Debian 服务器最小安装
- 具有 1GB 内存的 Ubuntu 服务器最小安装
- Node v6 LTS – 在 Debian 和 Ubuntu 中安装最新的 Node.js 和 NPM
- 安装了 Nginx 的 Debian/Ubuntu 服务器
重要:在您开始自行安装 Ghost 之前,您需要有一个良好的 VPS 托管,我们强烈推荐 BlueHost。
在本文中,我们将介绍如何在 Debian 和 Ubuntu 系统上安装开源 Ghost(内容管理系统)博客平台。
第 1 步:在 Debian 和 Ubuntu 上安装 Nodejs
1. Nodejs 在默认的 Debian 和 Ubuntu 软件存储库中不可用,因此首先添加其存储库,然后按如下方式安装。
sudo curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install nodejs
2. 安装 Nodejs 后,您可以使用命令验证是否安装了推荐版本的 Nodejs 和 npm。
node -v
npm -v
步骤 2:在 Debian 和 Ubuntu 上安装 Ghost
3. 现在创建一个 Ghost 根目录,将应用程序文件存储在 /var/www/ghost 中,这是推荐的安装位置。
sudo mkdir -p /var/www/ghost
4. 接下来,从 Ghost 的 GitHub 存储库获取最新版本的 Ghost,并将存档文件解压到您刚刚在上面创建的目录中。
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
sudo unzip -uo ghost.zip -d /var/www/ghost
5. 现在移动到新的 Ghost 目录,并使用以下命令安装 Ghost (仅限生产依赖项)。
sudo cd /var/www/ghost
sudo npm install --production
第 3 步:启动并访问默认 Ghost 博客
6. 要启动 Ghost,请从 /var/www/ghost 目录运行以下命令。
sudo npm start --production
7. 默认情况下,Ghost 应侦听端口 2368。要查看新设置的 Ghost 博客,请打开 Web 浏览器并输入以下 URL:
http://SERVER_IP:2368
OR
http://localhost:2368
注意:第一次启动Ghost后,会在Ghost根目录下创建config.js文件。您可以使用它来设置ghost的环境级别配置;您可以在其中配置站点 URL、数据库、邮件设置等选项。
步骤 4:为 Ghost 安装并配置 Nginx
9. 在本节中,我们将安装并配置 Nginx 以在端口 80 上服务器我们的 Ghost 博客,以便用户无需添加端口 :2368 即可访问 Ghost 博客
在网址末尾。
首先通过在终端上按 CTRL+C
键停止 Ghost 服务,然后如图所示安装 nginx。
sudo apt install nginx
systemctl start nginx
systemctl enable nginx
10. 安装 nginx 后,在 /etc/nginx/sites-available/ghost 下创建一个新文件。
sudo vi /etc/nginx/sites-available/ghost
添加以下配置并确保将以下突出显示的行更改为 your_domain_or_ip_address。
server {
listen 80;
server_name your_domain_or_ip_address;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:2368;
}
}
保存文件并通过在 /etc/nginx/sites-enabled 目录下创建符号链接来激活此配置。
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost
11.现在打开/etc/nginx.conf文件。将配置文件包含在 sites-enabled 目录中,并禁用默认站点,如图所示。
sudo vi /etc/nginx/nginx.conf
现在,在 http
块中添加以下行,以将配置文件包含在 sites-enabled 目录中。
http {
...
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
然后完全注释掉 http
块中找到的默认服务器块。
...
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
#
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#
location / {
}
#
error_page 404 /404.html;
location = /40x.html {
}
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
...
...
最后,保存并重新启动 nginx Web 服务器。
sudo systemctl restart nginx
再次访问 http://your_domain_or_ip_address
,您将看到您的 Ghost 博客。
欲了解更多信息,请访问 Ghost 官方网站:https://ghost.org/
就这样!在本文中,我们展示了如何在 Debian 和 Ubuntu 中设置 Ghost。通过下面的反馈表向我们发送您对本指南的疑问或任何想法。