CentOS下利用ghost部署个人博客

2018-12-23
折腾教程

GHOST 依赖

  • Node.js
  • Nginx
  • sqlite或者mysql

    安装Node.js

yum update -y
yum groupinstall -y "Development Tools"
curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
yum -y install nodejs
npm i -g cnpm

安装 Ghost Client

cnpm i -g ghost-cli

安装 Ghost

  • 添加 Ghost 运行用户并创建目录

    adduser ghost
    mkdir /var/www
    mkdir /var/www/ghost
    chown ghost /var/www/ghost
  • 安装 Ghost

    切换到ghost用户安装并启动ghost

    su ghost

    本教程以 SQLite3 作为 Ghost 的数据库。

    cd /var/www/ghost
    ghost install local --db=sqlite3
  • Ghost 停止、启动、重启命令

    ghost stop
    ghost start
    ghost restart

    安装成功后默认是运行在http://localhost:2368/,如果需要对外访问,则需要通过 Nginx 进行反向代理。

Nginx

  • 安装

    切换回root用户以免出现权限问题

    su root

    使用以下命令添加 CentOS 7 Nginx yum 资源库:

    rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    安装:

    yum install -y nginx
  • Nginx配置反向代理

    修改 config 文件(请确保 Ghost 已经在运行阶段方可进行如下操作。)

    vi /etc/nginx/conf.d/default.conf

    运行上面的命令后,再键入 i 然后移动光标在约第七行修改相关文件代码:

    location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    }

    改为:

    location / {
    proxy_pass http://127.0.0.1:2368;
    proxy_redirect default;
    root /usr/share/nginx/html;
    index index.html index.htm;
    }
  • 重启Nginx使配置生效

    systemctl restart nginx.service
  • 切换到ghost用户

    su ghost
  • 启动ghost

    ghost start
server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
proxy_pass http://127.0.0.1:2368;
proxy_redirect default;
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}