发布于 2014-12-30 09:43:15 | 279 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的精品教程,程序狗速度看过来!

Ghost 博客系统

Ghost 是一个开源的博客平台, 可以把他看作 WordPress 的一个挑战者. 现阶段的 WordPress 已经可以明显感觉到有些臃肿不堪, 无论是构架, 设计, 还是实现处处都显示出这是一个 10 年前就诞生的项目, 尤其是最近几个版本更新, 几乎都只是在功能和交互层面作出改进, 而看不到本质上的进步和优化. 因此我更愿意把 Ghost 看作 WordPress 的继任者. 同时, Ghost 基于 JavasSript 的 Node.js 进行开发, 在可预见的未来里, JS 无疑比 PHP 有着更多的优势.


本文为大家 讲解的是如何在在linux vps 上安装 Ghost 博客系统的方法,感兴趣的同学参考下。

ghost博客简介

Ghost是迄今为止最好用的开源博客平台。Ghost博客由前WordPress主管 John O'Nolan 和美女工程师 Hannah Wolfe 创立。开源社区支持率远超WordPress。

Ghost中文版由云应用托管服务商点云DianCloud主导开发和在中国区推广。中文版代码将在与官方版保持一致的前提下,加入一些特有功能。 比如:可以将博文转换成长微博,自动发布到用户绑定的微博上; 可以与用户的公众账号关联,自动生成图文消息并推送等等。

1. 前期准备

我的 VPS 系统比较差,很多必备的东西都没安装。

apt-get update
apt-get -y upgrade
apt-get install -y build-essential vim curl unzip

2. 安装 nodejs 和 npm

curl -sL https://deb.nodesource.com/setup | bash -
apt-get install -y nodejs

3. 安装 ghost

进入你想要安装的目录(一般我放在 /home/wwwroot/domain_name/ 下)执行:

curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip -uo ghost.zip
npm install --production
npm start

这样装好后,外网是访问不到的,因为生产环境只监听了127.0.0.1的请求。你可以修改 config.js 来修改设定,但是我们一般在前端再用一层 nginx 做中转。

4. 安装并配置 nginx

apt-get install -y nginx
rm /etc/nginx/sites-enabled/default
vi /etc/nginx/sites-available/ghost.conf

ghost.conf 的内容如下(注意替换里面的域名和配置域名指向):

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:2368;
    }
}

创建链接:

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

启动nginx:

service nginx start

这个时候你使用域名就可访问到了。

5. 配置后台运行

后台运行有很多方式,比如 forever 、Supervisor 等等。这里我们使用 Supervisor 。

apt-get install -y supervisor
service supervisor start
vi /etc/supervisor/conf.d/ghost.conf

内容如下(注意替换路径):

[program:ghost]
command = node /path/to/ghost/index.js
directory = /path/to/ghost
user = ghost
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"

执行以下代码启动 ghost :

service supervisor start
supervisorctl reload

如果遇到问题或修改了配置,可使用以下命令检查或重载:

supervisorctl tail -f ghost stderr
supervisorctl restart ghost
supervisorctl update

6. 优化 ghost 配置

经过之前的配置,现在ghost是可以访问到了,但是还会有一些问题,配置文件是 ghost 程序目录的 config.js,我们来修改下 production 字段的配置。

  • 根目录网址:配置url为你自己的url,不然会导致路径出错;
  • 增加 privacy字段,禁用后台的 google fonts 和 Gravatar (这两个国内被封):
privacy: {
    useGoogleFonts: false,
    useGravatar: false
}
  • 要禁用前台的 Google Fonts,只能手动修改模版中的 css 文件引用了。对于默认的 capser 主题,在 content/themes/capser/ 目录的 default.hbs 中。

  • 配置邮件在 mail 字段中。官方文档 中只介绍了使用 mailgun 等服务商的方式,如果是已经有了自己的邮件服务,可采用以下配置(以QQ域名邮箱为例,注意替换邮箱和密码):

mail:{
    transport: 'SMTP',
    from: 'Your Name <yourname@yourhost.com>',
    options: {
        host:'smtp.qq.com',
        secureConnection: false,
        port:25,
        auth: {
            user: 'your_email_addr',
            pass: 'your_email_password'
        }
    }
},


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务