如何在 Ubuntu 上搭建 Ghost 博客平臺?
Ghost 是一款開源的博客平臺,基于 Node.js,由前 WordPress UI 主管 John O’Nolan 和 WordPress 開發(fā)人員 Hannah Wolfe 創(chuàng)立。網(wǎng)上的開源博客程序眾多,去年剛上線的 Ghost 來勢洶洶正迅速捕獲用戶,0.4.1 這么早期的版本就讓 Coding Horror 擁抱了 Ghost。Ghost 主題/模版越來越多,一些優(yōu)秀的 WordPress 主題商,比如 WooThemes 都開始提供 Ghost 主題了。
安裝 Ghost 非常容易,甚至比 WordPress 還簡單。下面的安裝步驟在 Ubuntu 12.04.4 LTS Server 版本上測試通過。
切換到 root 賬號升級和更新整個系統(tǒng):
$ sudo -i # apt-get update # apt-get upgrade
安裝 Node.js 運行環(huán)境:
# apt-get install g++ make python python-software-properties # add-apt-repository ppa:chris-lea/node.js # apt-get update # apt-get install nodejs
下載、解壓 Ghost 后安裝:
# cd # wget https://ghost.org/zip/ghost-0.4.1.zip # unzip ghost-0.4.1.zip -d ghost # cd ghost # npm install --production
配置 Ghost 使其監(jiān)聽本機上的所有 IP,修改 ’127.0.0.1′ 為 ’0.0.0.0′:
# vi config.js ... server: { // Host to be passed to node's `net.Server#listen()` host: '0.0.0.0', // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT` port: '2368' } ...
使用 npm 啟動 Ghost 程序:
# npm start > ghost@0.4.1 start /root/ghost > node index Ghost is running in development... Listening on 0.0.0.0:2368 Url configured as: http://my-ghost-blog.com
Ghost 的默認(rèn)端口是 2366,打開瀏覽器訪問 http://192.168.2.178:2366 就可以看到界面了:
登錄后臺訪問 http://192.168.2.178:2366/admin 地址:
Ghost 是獨立程序,在 nodejs 環(huán)境下可以直接運行,在 config.js 文件里修改 Ghost 的監(jiān)聽端口 2366 為 80 就可以了,不過在生產(chǎn)環(huán)境我們一般在前端加個 Nginx.
安裝和配置 Nginx:
# apt-get install nginx # rm /etc/nginx/sites-enabled/default # vi /etc/nginx/sites-available/ghost server { listen 0.0.0.0:80; server_name vpsee.com; access_log /var/log/nginx/vpsee.com.log; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:2368; proxy_redirect off; } } # ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost # /etc/init.d/nginx restart
Nginx 接到請求后會 pass 給(proxy_pass)Ghost 服務(wù)程序,這時候最好把剛才測試用的 Ghost 配置修改還原成 ’127.0.0.1′,修改后記得重啟 Ghost:
# vi config.js ... // Host to be passed to node's `net.Server#listen()` host: '127.0.0.1', ...
每次 npm start 太麻煩,為了 Ghost 程序在系統(tǒng)啟動后能自動運行,需要加入腳本到 Upstart 里:
# vi /etc/init/ghost.conf start on startup script cd /root/ghost npm start end script
以后需要啟動、重啟或者停止 Ghost 就可以用 service ghost start/restart/stop 了:
# service ghost restart ghost stop/waiting ghost start/running, process 11619
相比 WordPress 的臃腫 Ghost 要輕爽得多。通過 Markdown 格式、Node.js 的實時和漂亮的界面,Ghost 給用戶提供了一種更簡單、更純粹的內(nèi)容寫作發(fā)布方式。左邊是編輯文章,右邊是實時預(yù)覽: