最近突然想自己搭建一個博客溅潜,網(wǎng)上搜了幾個自己搭建博客的方法,最后還是選擇了ghost。
以下是搭建步驟(此處是搭建在自己本地建的虛擬機服務器胚嘲,各位可以買vps或者阿里云服務器)
1、安裝node--版本Node v0.10.40
注意node和ghost的版本搭配
安裝完成驗證是否成功:
2强胰、安裝Nginx--版本1.80
首先在/etc/yum.repos.d/目錄下創(chuàng)建一個源配置文件nginx.repo
vi /etc/yum.repos.d/nginx.repo
寫入如下內(nèi)容:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
初始化好之后舱沧,執(zhí)行以下幾個命令就可以安裝并啟動Nginx
yum install nginx -y #安裝
啟動
start nginx.service
設置開機啟動
systemctl enable nginx.service
進入目錄:cd /etc/nginx/conf.d/
創(chuàng)建文件vi ghost.conf,寫入如下內(nèi)容:
server {
????listen 443;
????server_name yashon.comwww.yashon.com;
????location / {
????????proxy_set_header???X-Real-IP $remote_addr;
????????proxy_set_header???Host??????$http_host;
????????proxy_passhttp://127.0.0.1:2368;
????}
}
重啟Nginx:service nginx restart
3偶洋、安裝ghost
進入目錄:cd /var/www/
下載ghost:wgethttp://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
解壓:unzip Ghost-0.7.4-zh-full.zip -d ghost
進入ghost目錄:
修改目錄:cp config.example.js config.js
vi config.js
修改其中的production
說明幾點:
1)url就寫你之前在Nginx中配置的域名或者你服務器的IP
2)database:我使用了默認的sqlite3熟吏,因為ghost自帶了,當然也可以使用MySQL
3)server:寫你在Nginx中配置的IP和端口
4)storage:云存儲玄窝,支持阿里云牵寺,七牛等,因為我自己是在自己的建的虛擬機上安裝的恩脂,所以這個地方我使用了默認的local-file-store
啟動ghost:npm start --production
如果停止只需要按Ctrl+c即可
此處有個坑帽氓,使用ghost默認的sqlite3的話,啟動ghost訪問你的后臺管理系統(tǒng)xxx.com/ghost的話可能出現(xiàn)404俩块,如果出現(xiàn)這個錯誤建議還是使用MySQL
4黎休、安裝MySQL
centos7中yum源中沒有MySQL,所以要先下載MySQL的repo源
1)下載mysql的repo源
wgethttp://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
2)安裝mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
3)安裝mysql
sudo yum install mysql-server
4)設置密碼
如果出現(xiàn)以上錯誤:原因是/var/lib/mysql的訪問權(quán)限問題玉凯。下面的命令把/var/lib/mysql的擁有者改為當前用戶:
sudo chown -R root:root /var/lib/mysql