天天看點

從零開始,CentOS6安裝ghost部落格

買了個Bandwagon的VPS來科學上網的,尋思着空間還大順便做個部落格呗.

然後就安裝了AMH面闆,再搞了個wordpress部落格玩玩.

接觸到Ghost部落格的時候,心血來潮想裝一個. 然後就試着搞了.

安裝之後在Ngnix反向綁定域名之後,首頁沒格式了都亂了. 也不知道哪裡出了問題.

幹脆推倒重來,重新給VPS裝上了CentOS6x32系統. 接下來就是我一步步安裝到位的過程:

一. 首先用Xshell登陸SSH VPS

安裝LMNP環境包,具體看下面連結

http://lnmp.org/install.html

二. 檢查更新CentOS

yum update -y

yum install -y wget

三. 安裝Node.js

curl -sL https://rpm.nodesource.com/setup | bash -

yum install -y nodejs

四. 安裝Ghost

cd /home/wwwroot/

curl -L -O http://dl.ghostchina.com/Ghost-0.7.4-zh.zip

unzip -d ghost Ghost-0.7.4-zh.zip

cd ghost

sudo npm install --production

五. 修改配置

sudo vi config.example.js

在Production下修改

url:http://betears.com

host: '127.0.0.1:2368'

改為

host: '0.0.0.0:2368'

六. 建立ghost使用者并登入

useradd ghost

chown -R ghost:ghost /home/wwwroot/ghost/

su - ghost

cd /home/wwwroot/ghost/

npm start --production

然後就打開連結

http://betears.com:2368

就可以看到安裝完畢的ghost部落格了.

七. 以生産模式運作Ghost

我們不能讓其運作在開發模式. 需要讓其運作在生産模式,且當其運作程序退出時自動重新開機. 是以我們可以使用強大的程序守護程式“PM2”達到此目的. (也可以使用Forever)進入到剛才的Ghost安裝目錄 執行下面的指令安裝PM2:

sudo npm install pm2 -g

我們要設定環境變量為“production”生産模!“index.js”是程式啟動的入口. 最後給這個PM2的程序命名為"Ghost" 于是,執行下面的指令:

NODE_ENV=production pm2 start index.js --name "ghost"

讓PM2知道在開機後自動運作我們的網站:

pm2 startup centos pm2 save

八. Ngnix反向綁定域名

建立ghost.conf

Vim /usr/local/nginx/conf/vhost/ghost.conf

server { listen 80; server_name example.com; location / { proxy_set_header X-Real-IP remote_addr; proxy_set_header Host http_host; proxy_pass http://127.0.0.1:2368; } }

儲存退出:wq

最後 nginx -s reload

修改配置後重新加載生效. 打開網站OK

繼續閱讀