奇淫技巧

Ghost Ver 1.x安装笔记

前言

看到Ghost博客更新到1.x版本,就体验下了吧,中间也填了不少坑...

准备

Centos环境安装Ghost Blog(上)

Centos环境安装Ghost Blog(下)

以上俩篇文章Ghost版本是0.x,有兴趣的朋友可以读一读。

相对于现在的版本,有什么区别?

体验一把下来,主要是Ghost弄了个脚手架,可以一键式安装Ghost博客,有兴趣的朋友可以读下官方文档

官方文档需要准备的环境是:

  • Ubuntu 16.04
  • MySQL
  • Nginx (minimum of 1.9.5 for SSL)
  • Systemd
  • Node v6 installed via NodeSource

不过我测试的主机系统是腾讯云的Centos 7.2,安装下来也没问题。建议和官方环境一样即可。

Nginx、MySQL这类可以选择一键安装包完成,我用的是Oneinstack,这个我就不多说了,下面主要是Node.js安装和安装依赖的问题。

安装Node.js

如果安装官方文档来加入安装Node.js源,因为不可描述的原因,你会发现安装得很慢。所以这儿我推荐大家直接在仓库源安装吧:

apt-get install -y nodejs #Ubuntu

yum install -y nodejs #Centos

不过在安装之前你得需要查看Node.js版本是否符合官方的版本(V6):

apt-get info nodejs #Ubuntu

yum info nodejs #Centos

我的返回结果:

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Packages
Name        : nodejs
Arch        : x86_64
Epoch       : 1
Version     : 6.11.3
Release     : 1.el7
Size        : 4.6 M
Repo        : epel/7/x86_64
Summary     : JavaScript runtime
URL         : http://nodejs.org/
License     : MIT and ASL 2.0 and ISC and BSD
Description : Node.js is a platform built on Chrome's JavaScript runtime
            : for easily building fast, scalable network applications.
            : Node.js uses an event-driven, non-blocking I/O model that
            : makes it lightweight and efficient, perfect for data-intensive
            : real-time applications that run across distributed devices.

看到其中的Version : 6.11.3符合条件就行了。否则你需要按照下面的步骤来做。

官方文档说的是载入Node.js源:

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash 

然后刷新源安装Node.js:

apt-get update #Ubuntu
apt-get install -y nodejs #Ubuntu

yum update #Centos
yum install -y nodejs #Centos

这样Node.js环境安装好了。

替换国内npm环境

请参考 npm更换源,本文不在讲述。

安装Ghost

安装Ghost脚手架:

npm i -g ghost-cli

安装Ghost博客环境

我们需要创建个存放Ghost博客目录,例如我的放在/data/wwwroot/iiong.com

mkdir -p /data/wwwroot/iiong.com
cd /data/wwwroot/iiong.com
ghost install

期间会有提示安装数据库,根据自己的情况输入即可:

Nginx配置

下面我们该说说Nginx配置了,这儿我放个配置文件,你只需要把相关信息修改下即可:

upstream ghost_upstream {
    server unix:/dev/shm/socket.sock;
    keepalive 64;
}

proxy_cache_path /data/wwwroot/example.com/cache levels=1:2 keys_zone=STATIC:100m inactive=24h max_size=512m;  

server {
  listen 80;
  listen 443 ssl http2;
  ssl_certificate /usr/local/nginx/conf/ssl/example.com.crt;
  ssl_certificate_key /usr/local/nginx/conf/ssl/example.com.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 10m;
  ssl_session_cache builtin:1000 shared:SSL:10m;
  ssl_buffer_size 1400;
  add_header Strict-Transport-Security max-age=15768000;
  ssl_stapling on;
  ssl_stapling_verify on;
  server_name example.com www.example.com;
  access_log /data/wwwlogs/example.com_nginx.log combined;
#  index index.html index.htm index.php;
#  root /data/wwwroot/example.com;
  if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
  if ($host != example.com) {  return 301 $scheme://example.com$request_uri;  }
#  error_page 404 /404.html;
#  error_page 502 /502.html;

  location / {
    proxy_cache STATIC;
    proxy_cache_valid 200 60m;
    proxy_cache_valid 404 1m;
    proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
    proxy_ignore_headers Set-Cookie;
    proxy_pass http://ghost_upstream;
    proxy_redirect default;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forward-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    client_max_body_size     10m;
    client_body_buffer_size  512k;
    proxy_connect_timeout    5;
    proxy_read_timeout       60;
    proxy_send_timeout       5;
    proxy_buffer_size        16k;
    proxy_buffers            4 64k;
    proxy_busy_buffers_size  128k;
    proxy_hide_header Set-Cookie;
    proxy_hide_header    X-Powered-By;
    expires 10m;
    rewrite ^/(.*)\.html /$1/ permanent; #将WordPress重定向博文连接
    rewrite "\d{4}/\d{2}/\d{2}/(.*)$" /$1 permanent; #将WordPress/YYYY/MM/DD日期链接重定向博客首页
  }

  location ~ ^/(?:ghost|signout) {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://ghost_upstream;
    add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
    proxy_set_header X-Forwarded-Proto https;
    proxy_redirect off;
  }

  location = /favicon.ico { 
    alias /data/wwwroot/example.com/versions/1.16.0/core/server/public/favicon.ico;
  }

  location = /robots.txt { 
    alias /data/wwwroot/example.com/versions/1.16.0/core/server/public/robots.txt;
  }

  location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
    valid_referers none blocked *.example.com example.com www.example.com;
    if ($invalid_referer) {
        rewrite ^/ http://www.linuxeye.com/403.html;
        return 403;
    }
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }

#  location ~ .*\.(js|css)?$ {
#    expires 7d;
#    access_log off;
#  }

  location ~ /\.ht {
    deny all;
  }

}

Ghost配置文件:

{
  "url": "https://iiong.com",
  "server": {
    "socket": {
      "path": "/dev/shm/socket.sock",
      "permissions": "0666"
    }
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "127.0.0.1",
      "user": "数据库用户",
      "password": "数据库密码",
      "database": "数据库名"
    }
  },
  "mail": {
    "transport": "SMTP",
    "options": {
      "service": "qq",
      "auth": {
        "user": "用户名",
        "pass": "密码"
      }
    }
  },
  "privacy": false,
  "useMinFiles": true,
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/data/wwwroot/iiong.com/content"
  },
  "caching": {
    "frontend": {
      "maxAge": 0
    },
    "301": {
      "maxAge": 31536000
    },
    "customRedirects": {
      "maxAge": 31536000
    },
    "favicon": {
      "maxAge": 86400
    },
    "sitemap": {
      "maxAge": 3600
    },
    "robotstxt": {
      "maxAge": 3600000
    }
  }
}

完结

从目前来看,基本没什么问题了,中间踩了不少坑,不过都填好了。

虽然中间体验了几天,但是多少太简单了,还是用回WordPress博客平台。

本站内容遵循知识共享署名-非商业性使用-相同方式共享4.0 国际许可协议

转载原创文章请注明转自:Ghost Ver 1.x安装笔记

发表评论

理性发言,共建美好精神家园!