inux下安裝Ghost部落格平台
Ghost目前需要Node.js 0.10.X版本和npm 0.25支援,由於這兩個軟體包的版本要求比較嚴格,不要一味的求新,否則安裝會出問題
一、安裝和配置Ghost
1.安裝Nodejs:
curl --silent --location https://deb.nodesource.com/setup_0.10 | bash -
apt-get install --yes nodejs
2.把npm升級為2.5.0
npm install npm@2.5.0 -g
3.建立檔案夾目錄
mkdir -p /home/www/
4.下載ghost安裝包並解壓
cd /home
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip -uo ghost.zip -d www
cd www
5.安裝Ghost
npm install --production
複製一份預設的設定檔config.js(如有需要,可對此檔案進行進一步最佳化操作,本文此處暫可不更改)
cp config.example.js config.js
安裝好的ghost的連接埠為2368,已經可以進行本地的瀏覽和編輯了,但是,為了獲得更好的網路訪問體驗,還需要使用Nginx進行代理。
6.安裝Nginx
apt-get install nginx
cd /etc/nginx/
rm sites-enabled/default
vi /etc/nginx/sites-available/ghost
7.配置Nginx規則,只需要修改“your_domain.tld”為自己的網域名稱
server {
listen [::]:80;
server_name your_domain.tld;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
8.使Nginx規則生效
ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost
9.重啟Nginx
service nginx restart
10.為了方便我們日常的管理,可以將ghost註冊為Linux的服務(將Ghost添加為init.d),這樣也可以讓ghost安靜地在後台運行。
sudo curl https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost \
-o /etc/init.d/ghost
vi /etc/init.d/ghost
把GHOST_ROOT後面的目錄改為自己的Ghost目錄,本文為/home/www
11.由於上面的指令碼預設為系統的ghost使用者運行,因此,我們還需要建立使用者,並賦予他相應的許可權。
useradd -r ghost -U
chown -R ghost:ghost /home/www
chmod 755 /etc/init.d/ghost
經過以上設定,即可通過一般的service命令進行管理ghost的操作了
service ghost start
service ghost stop
service ghost restart
service ghost status
12.設定開機啟動
sudo update-rc.d ghost defaults
$ sudo update-rc.d ghost enable
13.訪問http://網域名稱/ghost/setup/one/,經過簡單幾步設定和建立賬戶,安裝就完成了。
二、發送郵件設定:
這裡採用Mailgun提供的SMTP服務,可以省去不少不必要的麻煩,另外,Mailgun提供的每月10,000封郵件的額度完全滿足一般個人部落格的需求
1.訪問如下網址,註冊帳號後,點擊賬戶內部的sandboxXXXX.mailgun.org的網域名稱,點進去可以看到API Key的字串,複製下來,在下面的網址上輸入
https://ghost.mailgun.com/
2.輸入部落格網域名稱
3.右邊會產生完整的Ghost的設定檔,複製其中的mail欄位
4.粘貼到Ghost設定檔/home/www/config.js相應的位置上。
5.重啟Ghost生效
service ghost restart