[关闭]
@52fhy 2016-01-03T13:55:09.000000Z 字数 5244 阅读 868

Ghost博客安装

Nodejs 博客


Ghost博客是一个基于Node.js 的开源博客平台,由前WordPress UI 部门主管John O’Nolan 和WordPress 高级工程师Hannah Wolfe 创立,目的是为了给用户提供一种更加纯粹的内容写作与发布平台。

目前来看,Ghost博客相对于Wordpress来说没有太明显的优势,现在的用户也都是码农们和喜欢尝鲜的朋友居多。当然Ghost博客体验良好的markdown编辑器、响应式前后台设计、采用的实时架构,让博客变得更有效率。

Ghost博客从2013年10月开始发布,现在已经更新了多个版本,各方面也逐渐完善起来了,但是普及率还有待于提高。Ghost需要Node.js环境和搭建难度过大,应该是Ghost博客推广的主要障碍。未来Ghost博客有很大的发展潜力。

安装Node运行环境

Node.js是一个可以快速构建网络服务及应用的平台,基于Chrome's JavaScript runtime,即Google V8引擎,是一款高性能的服务架构平台。

yum安装

  1. yum install nodejs(适用于Centos等)

apt-get方式安装(适用于Ubutun等)

  1. apt-get install nodejs

windows安装
直接下载安装包安装nodejs

命令行执行命令:node -v,可以查看是否成功安装Node.js,npm -v可以查看是否安装了npm。

如果没有安装npm,输入

  1. yum install npm

安装 Ghost

建议先阅读http://www.ghostchina.com/download/

Ghost 中文集成版下载(建议下载此版本,包含组件sqlite等)
最新版本:Ghost v0.7.0 full (zh)

  1. cd /www/
  2. #中文集成版
  3. wget http://dl.ghostchina.com/Ghost-0.7.0-zh-full.zip
  4. #中文标准版
  5. #wget http://dl.ghostchina.com/Ghost-0.7.0-zh.zip
  6. mkdir ghost
  7. cd ghost
  8. unzip Ghost-0.7.0-zh-full.zip

以上地址可能会更新,请以官网的为主。

本地测试运行

  1. cp config.example.js config.js

本地环境测试运行不用改任何配置(数据库默认使用SQLite):

  1. node index.js

正常运行会输出:

  1. Migrations: Up to date at version 004
  2. Ghost is running in development...
  3. Listening on 127.0.0.1:2368
  4. Url configured as: http://localhost:2368
  5. Ctrl+C to shut down

在浏览器输入http://localhost:2368即可。但是通过node index.js启动的会独占窗口,也不稳定,建议仅测试的时候用。

配置 Ghost 域名

设置域名解析

例如g.52fhy.com,添加A记录,设置记录值为主机的IP地址即可。

配置nginx

在/usr/local/nginx/conf/vhosts/新增一个配置文件g.52fhy.com.conf,内容为:

  1. server {
  2. listen 80;
  3. server_name g.52fhy.com;
  4. location / {
  5. proxy_set_header X-Real-IP $remote_addr;
  6. proxy_set_header Host $http_host;
  7. proxy_pass http://127.0.0.1:2368;
  8. }
  9. }

以上是Nginx作为Ghost博客的反向代理。

重启nginx

  1. /usr/local/nginx/sbin/nginx -s relaod

让 Ghost 一直运行

前面提到的启动 Ghost 使用 npm start 命令。这是一个在开发模式下启动和测试的不错的选择,但是通过这种命令行启动的方式有个缺点,即当你关闭终端窗口或者从 SSH 断开连接时,Ghost 就停止了。为了防止 Ghost 停止工作,有两种方式解决这个问题。

Forever

你可以使用 forever 以后台任务运行 Ghost 。forever 将会按照 Ghost 的配置,当进程 crash 后重启 Ghost。

  1. #注意production 为生产环境
  2. NODE_ENV=production forever start index.js
  1. [root@test ghost]# NODE_ENV=production forever start index.js
  2. warn: --minUptime not set. Defaulting to: 1000ms
  3. warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
  4. info: Forever processing file: index.js
  5. [root@test ghost]# forever list
  6. info: Forever processes running
  7. data: uid command script forever pid id logfile uptime
  8. data: [0] 0JVT /usr/bin/node index.js 12148 12157 /root/.forever/0JVT.log 0:0:0:1.555

Supervisor

流行的 Linux 发行版——例如 Fedora, Debian 和 Ubuntu,都包含一个 Supervisor 包:一个进程控制系统,允许在启动的时候无需初始化脚本就能运行 Ghost。不像初始化脚本一样,Supervisor 可以移植到不同的发行版和版本。

根据不同的 Linux 发行版 安装 Supervisor 。如下所示:

  1. [program:ghost]
  2. command = node /path/to/ghost/index.js
  3. directory = /path/to/ghost
  4. user = ghost
  5. autostart = true
  6. autorestart = true
  7. stdout_logfile = /var/log/supervisor/ghost.log
  8. stderr_logfile = /var/log/supervisor/ghost_err.log
  9. environment = NODE_ENV="production"

详细内容请参阅 Supervisor文档

增加评论

增加 CDN

使用 CDN 缓存页面可以加快访问速度,减轻服务器的压力。
免费的 CDN 有很多,这里就不列举了。

设置SMTP发邮件

给Ghost博客设置SMTP只需要编辑:vim config.js,在production下的Mail中加入SMTP信息即可。

  1. mail: {
  2. transport: 'SMTP',
  3. options: {
  4. service: 'Gmail',
  5. auth: {
  6. user: 'youremail@gmail.com',
  7. pass: 'yourpassword'
  8. }
  9. }
  10. }

Ghost博客Google Fonts字体、备份和设置Apache反代

1、Ghost博客默认的主题加载了Google Fonts,导致博客打开变慢或者根本上打不开,解决的办法就是去掉主题中加载的Google Fonts链接。

2、Ghost博客后台去掉Google Fonts需要进入到:core/server/views/default.hbs·和·core/server/views/user-error.hbs,把里面的fonts.googleapis.com链接删除了。

3、默认的主题去掉Google Fonts需要进入到:content/themes/casper/default.hbs,把里面的fonts.googleapis.com链接删除了。

4、Ghost博客备份与恢复。Ghost 博客的所有文章内容都是存储在 sqlite3 数据库中的,其位置是 /content/data/ghost.db。另外,所有上传的图片都放在了 /content/images/ 目录下。

5、Ghost博客自带了一个备份与恢复的页面,地址是:域名/ghost/debug/。 点击 Export 按钮就可以将博客内容导出为 .json 文件,还有一个导入工具 Import ,可以将 .json 格式的备份内容导入Ghost 系统。 最后一个红色按钮 Delete all content 是用来删除所有内容(即清空数据库)。

6、设置Apache反代。本文中使用了Nginx作为Ghost博客的反代,如果你喜欢使用Apache,可以用以下代码实现Apache反代Ghost。

7、CentOS(或Redhat)系统中,Apache 的配置文件位于/etc/httpd/conf.d目录下;而 Ubuntu 系统中则是位于 /etc/apache 目录下。将下面给出的这段配置信息添加到 Apache 的配置文件中(注意替代成你的域名):

  1. NameVirtualHost *:80
  2. <VirtualHost *:80>
  3. ServerName your-domain-name.com
  4. ServerAlias www.your-domain-name.com
  5. ProxyRequests off
  6. ProxyPass / http://127.0.0.1:2368/
  7. ProxyPassReverse / http:/127.0.0.1:2368/
  8. </VirtualHost>

8、如果你想用Apache反代多个Ghost博客,使用以下代码:

  1. NameVirtualHost *:80
  2. <VirtualHost *:80>
  3. ServerName your-domain-name.com
  4. ServerAlias www.your-domain-name.com
  5. ProxyRequests off
  6. ProxyPass / http://127.0.0.1:2368/
  7. ProxyPassReverse / http:/127.0.0.1:2368/
  8. </VirtualHost>
  9. <VirtualHost *:80>
  10. ServerName yoursecond--domain-name.com
  11. ServerAlias www.yoursecond--domain-name.com
  12. ProxyRequests off
  13. ProxyPass / http://127.0.0.1:8080/
  14. ProxyPassReverse / http://127.0.0.1:8080/
  15. </VirtualHost>

9、最后重启 Apache生效。
在 CentOS 系统中执行如下命令: service httpd restart
在 Ubuntu 系统中执行: service apache2 restart

DIY 一个主题

参考官方文档 http://themes.ghost.org/

参考:
1、在树莓派上搭建一个博客
http://blog.eqoe.cn/posts/website-on-raspberry-pi.html
2、Ghost博客安装与使用教程-Node.js,Nginx,MySQL,Ghost搭建与配置
http://www.freehao123.com/ghost-node-js/
3、http://www.ghostchina.com/download/
4、http://docs.ghostchina.com/zh/installation/deploy/
5、supervisor安装配置与使用 - 其他 - 红黑联盟
http://www.2cto.com/os/201503/378878.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注