LNMP 环境搭建+反向代理+使用forever 运行ghost

一、下载并安装LNMP一键安装包:

执行安装程序前须要您确认您的Linux发行版,能够执行:cat /etc/issue 查看是CentOS、Debian仍是Ubuntu,也能够经过VPS服务商提供的控制面板上查看。肯定好以后,选择下面对应系统的安装命令:php

CentOS系统下执行:html

wget -c http://soft.vpser.net/lnmp/lnmp1.1-full.tar.gz && tar zxf lnmp1.1-full.tar.gz && cd lnmp1.1-full && ./centos.sh

Debian系统下执行:node

wget -c http://soft.vpser.net/lnmp/lnmp1.1-full.tar.gz && tar zxf lnmp1.1-full.tar.gz && cd lnmp1.1-full && ./debian.sh

Ubuntu系统下执行:mysql

wget -c http://soft.vpser.net/lnmp/lnmp1.1-full.tar.gz && tar zxf lnmp1.1-full.tar.gz && cd lnmp1.1-full && ./ubuntu.sh

而后根据提示输入mysql密码、php版本之类的配置,详情查看http://lnmp.org/install.htmlnginx

二、Nginx反向代理

LNMP的nginx conf文件位置:/usr/local/nginx/conf/;sql

  1. 在conf下使用 mkdir vhost,新建vhost 文件夹,若是有则跳过;由于nginx.conf会引入vhost/*.conf;
  2. 一个简单的反向代理脚本:npm

    nginxserver {
        listen 80;
        server_name domain.com;
        location / {
            proxy_set_header   Host      $http_host;
            proxy_pass         127.0.0.1:2368;
            proxy_redirect      off;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    proxy_pass 127.0.0.1:2368;//127.0.0.1 和 2368 对应你在 ghost中config.js 的配置ubuntu

    domain.com替换成须要的域名;centos

  3. 配置完成后,须要刷新nginx配置,如下2条命令均可以:bash

    bash/root/lnmp reload
    /etc/init.d/nginx reload

至此就将全部来自domain.com:80的访问代理到domain.com:2368端口了;

三、安装Node.js

  1. 检查是否安装了epel;

    bashyum repolist

若是没有在结果中看到epel则经过yum命令安装:
若是你的版本是centos6.x请使用如下命令:

bashyum install \
    http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

若是你的版本是centos7.x请使用如下命令

bashyum install \
    http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

安装好以上环境以后就安装nodejs以及npm

bashyum install nodejs npm --enablerepo=epel

四、安装forever

启动 Ghost 可使用 npm start 命令。这是一个在开发模式下启动和测试的不错的选择,可是经过这种命令行启动的方式有个缺点,即当你关闭终端窗口或者从 SSH 断开链接时,Ghost 就中止了。为了防止 Ghost 中止工做,咱们须要 Forever

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

  1. 经过 npm install forever -g 安装 forever
  2. 为了让 forever 从 Ghost 安装目录运行,输入 NODE_ENV=production forever start index.js
  3. 经过 forever stop index.js 中止 Ghost
  4. 经过 forever list 检查 Ghost 当前是否正在运行

使用NODE_ENV=production forever start index.js运行的缘由能够参看这里http://docs.ghost.org/zh/usage/configuration/


原文地址: http://nero-zou.com/init-set/

相关文章
相关标签/搜索