IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    VPS上安装Ghost

    五月里徜徉的小猫咪发表于 2014-01-28 11:47:23
    love 0

    小猫咪我搞了一下那个叼炸天的Nodejs的博客程序,叫什么,Ghost,诶,没错儿就是它了,号称在Kickstarter上融资N多,前Wordpress工程师作为这个程序的Leader,等等吧,反正很牛逼就是了,下面说一下怎么安装它,和PHP非常不一样,还算是比较麻烦的。

    需求说明

    1.Python 2.6或者更高
    2.需要Nginx和MySQL
    3.Ghost也支持其他数据库,如PostgreSQL和SQLite
    4.本文以MySQL为例

    准备工作

    准备好Python

    这点非常重要,因为编译Nodejs的时候需要Python来进行编译,如果各种依赖性问题的话,你可能会像我一样悲剧,为了解决Python而花掉大把的时间。别的就不用多说了吧,准备好Python我们就可以开始工作了。我们用如下命令安装Python以及Nodejs

    sudo apt-get install python-software-properties
    sudo apt-add-repository ppa:chris-lea/node.js 
    sudo apt-get update 
    sudo apt-get install nodejs

    配置MySQL

    连接好数据库,我们需要创建两个库,我们创建一个ghostdev和一个ghost,两个库,我们可以通过命令行进行创建,也可以通过PhpMyAdmin进行创建,但是要记好我们的用户名密码哟

    配置好Nginx

    更改Nginx.conf,内容如下:

    server {
    listen 80;
    server_name ghost.catinmay.com;#此处填写你的域名
    location / {
          proxy_redirect off;
          proxy_set_header   X-Real-IP            $remote_addr;
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header   X-Forwarded-Proto $scheme;
          proxy_set_header   Host                   $http_host;
          proxy_set_header   X-NginX-Proxy    true;
          proxy_set_header   Connection "";
          proxy_http_version 1.1;
          proxy_cache one;
          proxy_cache_key ghost$request_uri$scheme;
          proxy_pass         127.0.0.1:2386; #此处是Ghost程序运行的端口
        }

    下载程序并配置

    wget https://ghost.org/zip/ghost-0.4.0.zip
    unzip ghost-0.4.0.zip

    我们进入网站目录,然后运行如下命令

    sudo npm install --production
    sudo npm install mysql
    sudo npm install forever -g

    我们用forever呢,来监控这个Ghost程序,一旦崩溃,就自动重启。
    创建一个重启的脚

    sudo nano -w /var/www/starter.sh

    粘贴如下内容到这个文件中

    #!/bin/sh
    if [ $(ps aux | grep node | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
    then
        export PATH=/usr/local/bin:$PATH
        export NODE_ENV=production
        NODE_ENV=production forever start --sourceDir /var/www index.js >> /var/log/nodelog.txt 2>&1
    fi

    为脚本添加可执行权限并修改网站所有者

    sudo chmod +x /var/www/starter.sh
    sudo chown -R www-data:www-data /var/www/

    编辑我们的crontab

    crontab -e

    把下面的内容粘贴到里面

    @reboot /var/www/starter.sh

    在我们的解压目录下有个config.js我们编辑它

    development: {
        // The url to use when providing links to the site, E.g. in RSS and email.
        url: 'http://你的域名',

    以及production段

    production: {
        url: 'http:// 你的域名',

    配置数据库

    在development段配置如下

    database: {
                client: 'mysql',
                connection: {
                        host: 'localhost',
                        user: '数据库用户名',
                        password: '数据库密码',
                        database: 'ghostdev',
                        charset: 'utf8'
                }
        },

    同理,我们在production段配置也类似,但是我们用另外一个数据库

    database: {
                client: 'mysql',
                connection: {
                        host: 'localhost',
                        user: 'ghost',
                        password: 'YOUR_PASSWORD',
                        database: 'ghostdev',
                        charset: 'utf8'
                }
        },

    全部设置好之后,我们就可以运行了

    sudo ./starter.sh

    第一次可以通过访问http://域名/ghost 设置你的登陆密码,而这个地址则为你的后台管理地址。



沪ICP备19023445号-2号
友情链接