Ghost搭建個人博客

 

搭建環境

Centos 7.6

騰訊雲

nginx

nodejs10

Ghost

  •  

‌‌

一、開發環境搭建

1、安裝Nodejs

yum update -y
yum groupinstall -y "Development Tools"
curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -
yum -y install nodejs
npm config set registry https://registry.npm.taobao.org //配置加速
npm i -g cnpm

安裝成功後通過運行node -v及npm -v 出現版本號即可表示安裝成功。

因爲國內網絡的關係,也同時安裝了 cnpm 模塊,後續將使用該命令代替 npm 命令。

2、安裝MySQL及其配置

安裝mysql

rpm -ivh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm 
yum -y install mysql-server mysql
systemctl start mysqld.service

配置mysql

mysql 
mysql> create database ghost;
mysql> grant all on ghost.* to 'ghost'@localhost identified by 'ghost';//密碼:ghost
mysql> flush privileges;

3、安裝Ghost-cli

cnpm i -g ghost-cli

安裝成功後通過運行 ghost -v,出現版本號即可表示安裝成功。

4、安裝Ghost

創建ghost用戶

adduser ghost
mkdir /var/www
mkdir /var/www/ghost
chown ghost /var/www/ghost

配置sudo權限

groupadd sudo
chown -R ghost:sudo /home/ghost/
chmod 775 /home/ghost/
usermod -aG sudo ghost

切換用戶安裝

su ghost
cd /var/www/ghost
ghost install local --db mysql

根據提示輸入相關信息,即可

[ghost@ming ghost]$ ghost install local --db mysql
✔ Checking system Node.js version
✔ Checking current folder permissions
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
☱ Downloading and installing Ghost v1.22.3 > Installing dependencies > [3/5] Fetching packages...

等得花兒都謝了,music...唱,跳,rab,籃球。。。。。

? Enter your MySQL hostname: localhost
? Enter your MySQL username: ghost
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost
✔ Configuring Ghost
✔ Setting up instance
✔ Running database migrations
ℹ Ensuring user is not logged in as ghost user [skipped]
ℹ Checking if logged in user is directory owner [skipped]
✔ Checking current folder permissions
✔ Validating config
✔ Checking memory availability
✔ Starting Ghost
You can access your blog at http://localhost:2368/

Ghost uses direct mail by default
To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config

5、查看ghost

ghost ls

可以看到ghost現在是運行在開發模式development下,下面修改爲生產模式

ghost stop
cp config.development.json config.production.json

在配置文件裏面修改url,改成你自己的域名即可

vi config.production.json

"url": "http://www.pplibaby.com/" //例如本站的域名或者主機的ip地址

ghost start//重啓ghost

6、Nginx 配置反向代理

使用以下命令切換到 root 用戶

su root

添加 CentOS 7 Nginx yum 資源庫:

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝Nginx

yum install -y nginx

啓動Nginx

systemctl start nginx.service

將Nginx加入開機啓動項

systemctl enable nginx.service

修改Nginx配置文件

cd /etc/nginx/conf.d/
vi ghost.conf

 server {  
     listen 80;
     server_name www.pplibaby.com;

 location / {
     proxy_set_header   X-Real-IP $remote_addr;
     proxy_set_header   Host      $http_host;
     proxy_pass         http://127.0.0.1:2368;
     proxy_redirect default;
     root   /usr/share/nginx/html;
     index  index.html index.htm;
    }
 }

運行 nginx -s reload 重啓 Nginx。

到此爲止,一個屬於你的個人博客就搭建成功啦

  •  

 

Photo by Gabrielle Henderson / Unsplash

  •      
  •      
  •  
  •      
  •                  
  •                  
  •                  
  •  
  •                  

 

參考文章:

  https://segmentfault.com/a/1190000014442264

  https://cloud.tencent.com/developer/labs/search?keyword=ghost

 關於我:http://www.pplibaby.com/

 

微信掃碼關注我

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章