十步配置centos+nginx环境下的ghost博客系统
网上有很多关于部署ghost的方法,看了不下几十篇终于搞定了。
环境如下:ghost blog0.5.7官方版、centos 6.5 64位、nginx 1.0.15、nodejs v0.10.35、npm 1.4.28
其实安装和编译是非常快的,我直接用yum安装,很省时间,主要就是配置nginx和ghost太麻烦了。
第一步:yum安装nginx和nodejs:
yum install nginx
第二步:通过nodejs官网的包管理器安装:
第三步:确认node和npm是否安装成功:
node -v
npm -v
如果出现版本号说明安装成功了。
第四步:安装forever,在这里要强调!!!最近很流行的pm2虽说远超forever几条街,但是在阿里云上只要开pm2,CPU就直接飙到100%,那你的ghost博客就访问不了了,这也是apache+ghost报503错误、nginx+ghost报502错误的隐藏bug,据说是由于pm2版本bug所致,以观后效吧!
第五步:下载官方ghost,国内的话应该还是主要用mysql的比较多吧,既然用不到sqlite3,我就干脆在安装直接把它删掉,以免后面报错麻烦,看着也闹心~
- 修改官方下载包中的
package.json文件,在第63~64行处删除"sqlite3": "3.0.2",,这样后面我们就用不到sqlite3了,也就不会出现ghost所使用的sqlite3报错的问题了。 - 然后拷贝文件夹中的
config.example.js文件并重命名为config.js文件,修改第13行,将url修改为你的域名(注意是绝对路径),然后将15~21行注释掉。
//database: {
// client: 'sqlite3',
// connection: {
// filename: path.join(__dirname, '/content/data/ghost.db')
// },
// debug: false
//},
- 注释之后,粘贴下面代码至你的
22行处:
database: {
client: 'mysql',
connection: {
host : 'xxxx',//数据库地址
user : 'xxx', //用户名
password : 'xxx', //密码
database : 'xxxz', //数据库名
charset : 'utf8'
}
},
- 至此文件修改完成,上传到你的vps上。
第六步:配置nginx反向代理,如果没有指定nginx安装目录的话,配置文件在/etc/nginx/conf.d下,编辑default.conf文件如下:
#
# The default server
#
server {
listen 80;
server_name xxx.com www.xxx.com;//你的域名
#charset koi8-r;
#access_log logs/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
root /xxx;//你的ghost安装目录
index index.html index.htm index.js;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/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;
#}
}
第七步:修改ghost的config.js文件,将第35行修改为:
host:'0.0.0.0',
第八步:安装ghost:
npm install --production
第九步:部署forever让ghost一直运行(需要当前所在目录为ghost博客所在目录):
NODE_ENV=production forever start index.js
第十步:开启nginx服务:
/etc/init.d/nginx start
至此,ghost博客部署完成!
浙公网安备 33010602011771号