Centos下部署firekylin博客系統

Firekylin 是一款基於 ThinkJS 開發的開源 NodeJS 博客系統,本實驗將帶你從零開始快速搭建自己的 Firekylin 個人博客

alt

1、安裝 Node.js

使用 yum 命令安裝 Node.js

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum -y install nodejs

2、使用 NPM 安裝 PM2

通過 NPM 安裝進程管理模塊 PM2。它是 Node.js 的一個進程管理模塊,之後我們會使用它來管理我們的個人網站進程。

npm install  //執行node依賴安裝
npm install pm2 -g  //使用pm2管理nodejs服務

3、安裝 MySQL

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server -y

啓動 MySQL 服務:

service mysqld restart

設置 MySQL 賬戶:

/usr/bin/mysqladmin -u root password 'Password4Firekylin'

4、安裝 Nginx

在 CentOS 上,可直接使用 [yum] 來安裝 Nginx

yum install nginx -y

5、安裝並配置 Firekylin

安裝 Firekylin

在服務器上下載安裝包

wget https://firekylin.org/release/latest.tar.gz

安裝程序依賴

cd firekylin
npm install

複製項目下的 pm2_default.json 文件生成新文件 pm2.json

cp pm2_default.json pm2.json

修改 pm2.json 文件中的 cwd 配置值爲項目的當前路徑 /root/firekylin:

{
  "apps": [{
    "name": "firekylin",
    "script": "www/production.js",
    "cwd": "/root/firekylin",
    "exec_mode": "fork",
    "max_memory_restart": "1G",
    "autorestart": true,
    "node_args": [],
    "args": [],
    "env": {

    }
  }]
}

然後通過以下命令啓動項目

pm2 startOrReload pm2.json

Firekylin 已經啓動成功,使用瀏覽器直接訪問 http://<您的 CVM IP 地址>:8360/ 即可看到 Firekylin 的配置界面。

配置信息

alt

配置完成後可以通過後臺管理帳號設置的帳號和密碼登錄博客管理後臺,截圖如下所示:

alt

6、配置 Nginx

下面我們就配置 Nginx 使用域名訪問我們的網站了。

複製項目下的 nginx_default.conf 爲 nginx.conf

cp nginx_default.conf nginx.conf

修改 nginx.conf 文件

server {
    listen 80;
    server_name www.yourdomain.com; #將 www.yourdomain.com 替換爲之前註冊並解析的域名
    root /root/firekylin;
    set $node_port 8360;

    index index.js index.html index.htm;

    location ^~ /.well-known/acme-challenge/ {
      alias /root/firekylin/ssl/challenges/;
      try_files $uri = 404;
    }

    location / {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://127.0.0.1:$node_port$request_uri;
        proxy_redirect off;
    }

    location = /development.js {
        deny all;
    }
    location = /testing.js {
        deny all;
    }

    location = /production.js {
        deny all;
    }
}

將 nginx.conf 文件軟鏈到 nginx 配置目錄下

ln -s /root/firekylin/nginx.conf /etc/nginx/conf.d/firekylin.conf

重啓 Nginx

service nginx restart

server_name 的值爲你的域名,root 爲你的項目所在路徑,$node_port 的值爲 Firekylin 啓動端口,默認爲 8360。

大功告成!

恭喜,您的 Firekylin 已經部署完成,盡情折騰吧:

博客訪問地址:http://<您的域名>

博客後臺地址:http://<您的域名>/admin

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