网站搜索

如何在CentOS 7中安装Ghost(CMS)博客发布平台


Ghost 是一款免费、开源、简单但功能强大的博客或在线出版软件,用 Nodejs 编写。它是一组现代出版工具,旨在轻松构建和运行在线出版物。

幽灵特点:

  • 快速、可扩展且高效。
  • 提供基于 Markdown 的编辑环境。
  • 附带桌面应用程序。
  • 配有漂亮的车把模板。
  • 支持简单的内容管理。
  • 支持作者、编辑和管理员的多重角色。
  • 允许提前安排内容。
  • 支持加速移动页面。
  • 全面支持搜索引擎优化。
  • 提供详细的结构化数据。
  • 支持RSS、Email、Slack订阅。
  • 实现简单的站点编辑等等。

要求:

  1. 具有 1GB 内存的 CentOS 7 服务器最小安装
  2. 具有静态IP地址的CentOS 7系统
  3. Node v6 LTS – 在 CentOS 7 中安装最新的 Node.js 和 NPM
  4. 安装了 Nginx 的 CentOS 7 服务器

重要:在您开始自行安装 Ghost 之前,您需要有一个良好的 VPS 托管,我们强烈推荐 BlueHost。

在本文中,我们将介绍如何在 CentOS 7 系统上安装开源 Ghost内容管理系统)博客平台。

步骤1:在CentOS 7上安装Nodejs

1. Nodejs在CentOS的软件仓库中不可用,因此首先添加其仓库,然后安装如下

curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
yum -y install nodejs npm
dnf -y install nodejs npm   [On Fedora 22+ versions]

2. 安装 Nodejs 后,您可以使用命令验证是否安装了推荐版本的 Nodejs 和 npm。

node -v 
npm -v

步骤2:在CentOs 7上安装Ghost

3. 现在创建 Ghost 根目录,将应用程序文件存储在 /var/www/ghost 中,这是推荐的安装位置。

mkdir -p /var/www/ghost

4. 接下来,从 Ghost 的 GitHub 存储库下载最新版本的 Ghost,并将存档文件解压到您刚刚创建的目录中。

curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip -uo ghost.zip -d  /var/www/ghost

5. 现在移动到新的 Ghost 目录,并使用以下命令安装 Ghost(仅限生产依赖项)。第二个命令完成后,Ghost 就应该安装在您的系统上。

cd /var/www/ghost 
npm install --production

第 3 步:启动并访问默认 Ghost 博客

6. 要启动 Ghost,请从 /var/www/ghost 目录运行以下命令。

npm start --production

7. 默认情况下,Ghost 应在端口 2368 上运行,因此请在防火墙上打开该端口以允许访问。

firewall-cmd --zone=public --permanent --add-port=2368/tcp
firewall-cmd --reload

8. 现在打开网络浏览器并导航至以下任一 URL。

http://SERVER_IP:2368
OR
http://localhost:2368

注意:第一次运行Ghost后,会在Ghost根目录下创建config.js文件。您可以使用它来设置ghost的环境级别配置;您可以在其中配置站点 URL、数据库、邮件设置等选项。

步骤 4:为 Ghost 安装并配置 Nginx

如果未使用 EPEL 存储库安装 Nginx Web 服务器,请安装并启动 Nginx Web 服务器,如图所示。

yum install epel-release
yum install nginx
systemctl start nginx

如果您正在运行防火墙,请使用以下命令启用对 HTTP 和 HTTPS 流量的访问。

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

下一步是配置 Nginx 在端口 80 上为我们的 Ghost 博客提供服务,以便用户无需在 URL 末尾添加端口 :2368 即可访问 Ghost 博客。

首先通过在终端上按 CTRL+C 键来停止正在运行的 Ghost 实例。

现在通过在 /etc/nginx/sites-available/ghost 下创建一个新文件来配置 Nginx。

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 目录下创建符号链接来激活此配置。

ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

现在打开 /etc/nginx.conf 文件。将配置文件包含在 sites-enabled 目录中,并禁用默认站点,如图所示。

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 服务器。

systemctl restart nginx

再次访问 http://your_domain_or_ip_address,您将看到您的 Ghost 博客。

欲了解更多信息,请访问 Ghost 主页:https://ghost.org/

在本文中,我们解释了如何在 CentOS 7 中安装和配置 Ghost。请使用下面的评论表向我们发送您的疑问或有关本指南的任何想法。

最后但并非最不重要的一点是,在下一篇文章中,我们将展示如何在 Debian 和 Ubuntu 中设置 Ghost。在此之前,请保持与 Howtoing.com 的连接。