在CentOS上搭建基於Nodejs的Ghost博客
阿新 • • 發佈:2018-04-23
Ghost 博客 nodejs 博客系統 Ghost介紹
Ghost 是基於 Node.js 構建的開源博客平臺。Ghost 具有易用的書寫界面和體驗,博客內容默認采用Markdown 語法
書寫。Ghost 的目標是取代臃腫的 Wordpress。
搭建Ghost博客系統
1、本機測試環境
[root@mingc ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@mingc ~]# uname -r
3.10.0-514.26.2.el7.x86_64
2、 安裝Node.js
#更新yum源 [root@mingc ~]# yum update -y #安裝軟件組包Development Tools [root@mingc ~]# yum groupinstall -y "Development Tools" #安裝NodeSource Node.js 6.x repo [root@mingc ~]# curl --silent --location https://rpm.nodesource.com/setup_6.x | bash - #yum安裝 nodejs [root@mingc ~]# yum -y install nodejs #npm國內鏡像(npm是隨同NodeJS一起安裝的包管理工具) [root@mingc ~]# npm config set registry https://registry.npm.taobao.org #安裝cnpm模塊(因為國內網絡的關系,也同時安裝了 cnpm 模塊,後續將使用該命令代替 npm 命令。) [root@mingc ~]# npm i -g cnpm
#通過node -v 和npm -v命令查看是否安裝成功。
3.、安裝 ghost
①安裝 Ghost Client (ghost-cli)
[root@mingc ~]# cnpm i -g ghost-cli
#安裝成功後通過運行 ghost -v,出現版本號即可表示安裝成功。
[root@mingc ~]# ghost -v
Ghost-CLI version: 1.7.1
②添加 Ghost 運行用戶並創建目錄
[root@mingc ~]# adduser ghost [root@mingc ~]# mkdir /var/www [root@mingc ~]# mkdir /var/www/ghost [root@mingc ~]# chown ghost /var/www/ghost
③安裝SQLite3 數據庫
#新版本不允許root用戶安裝,需要切換普通用戶進行安裝。
[root@mingc ~]# su - ghost
[ghost@mingc ~]$ cd /var/www/ghost
[ghost@mingc ~]$ ghost install local --db=sqlite3
④啟動 ghost
安裝成功後 Ghost 默認就已經啟動的
# 停止host [ghost@mingc ghost]$ ghost stop # 啟動ghost [ghost@mingc ghost]$ ghost start #重啟ghos [ghost@mingc ghost]$ ghost restart
安裝成功後默認是運行在http://localhost:2368/
可使用如下方式訪問:
[ghost@mingc ghost]$ curl http://localhost:2368/
4. 安裝 Nginx和整合nodejs
[ghost@mingc ghost]$ su - root
[root@mingc ~]# yum install -y nginx
#啟動 Nginx
[root@mingc ~]# systemctl start nginx.service
#查看nginx是否運行
[root@mingc ~]# ps -ef|grep nginx
#查看是否啟動成功 http://你的ip
#設置開機自啟動
[root@mingc ~]# systemctl enable nginx.service
#整合nodejs
[root@mingc ~]#cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.ori
[root@mingc nginx]# vi /etc/nginx/nginx.conf +47
server {
···
location / {
proxy_pass http://127.0.0.1:2368;
proxy_redirect default;
root /usr/share/nginx/html;
index index.html index.htm;
}
···
[root@mingc nginx]# nginx -s reload
4. 訪問搭建的ghost博客
前臺頁面:http://你的ip/
後臺登錄頁面:http://你的ip/ghost
後臺管理頁面:
以上搭建過程本人親自操作可用,有問題可留言評論,抽空予以解答,覺得有用點個贊,支持下作者!
在CentOS上搭建基於Nodejs的Ghost博客