首页 编程开发osx下使用Ghost搭建博客

osx下使用Ghost搭建博客

分类:编程开发
字数: 1570
评论: 0
阅读: 2928
摘要:

搭建流程

  • 系统:OS X EI Capiton 10.11.5
  • node: v4.2.6 (仅支持 0.10.x, 0.12.x and 4.2+ ,仅支持LTS版本 为什么?)
  • npm: 2.14.12

1.下载Ghost博客源码。

wget https://ghost.org/archives/ghost-0.8.0.zip
unzip ghost-0.8.0.zip -d ghost
cd ghost

2.安装依赖

请确保您的node版本为LTS 0.10.x, 0.12.x and 4.2+

npm install --production

启动Ghost

npm start --production

3.修改配置

将根目录config.js中production配置项urlmail设置好

production: {
    url: 'https://my-ghost-blog.com',
    mail: {
    transport: 'SMTP',
    options: {
    service: 'smtp.126.com',
    auth: {
    user: '', // 126 username
    pass: ''  // 126 password
    }
    }
    },
    ...

4.配置nginx

nginx安装教程

brew install nginx

安装好后运行

sudo nginx

启动之后可以通过 https://localhost:8080 来访问站点。

配置你的nginx

编辑nginx配置文件/usr/local/etc/nginx/nginx.conf 修改server相关配置

server {
     listen 80;
     server_name my-ghost-blog.com;

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

重启nginx

sudo nginx -s stop
sudo nginx

测试
更改 /etc/hosts,使 my-ghost-blog.com 指向 127.0.0.1
在浏览器中访问 https://my-ghost-blog.com 即可打开Ghost博客。

5.运行forever

此时虽然可以通过nginx访问到Ghost博客。但是npm是运行在终端上的,终端一旦关闭,npm的服务就会停止运行。通过自己的域名就无法访问到Ghost博客。为了防止 Ghost 停止工作,我们可以使用npm包forever来解决这个问题。
https://npmjs.org/package/forever

安装 forever

npm install forever -g

运行 forever

在Ghost根目录运行
NODE_ENV=production forever start index.js

停止 forever

forever stop #id(这个id可以通过forever list查看到)

查看运行着的 forever

forever list

这是在本地运行的Ghost,通过这个教程,也可以在vps上搭建。仅需将更改 hosts 这一步改为域名绑定。一般vps的控制面板都会有域名绑定的功能。

更多Ghost配置见官方文档

文章发布于: 2016-06-07 08:25:00

扫描二维码,在手机上阅读