Halo項目位址:https://github.com/ruibaby/halo
最近重新搭建了一下部落格系統,使用的是Halo部落格系統,現将搭建過程和配置Https的步驟記錄一下。
- 伺服器提供商使用的是騰訊雲
- 域名購買是在阿裡雲
- Https證書是在騰訊雲申請
- 伺服器系統安裝的是CentOS 7.4 64位
- 此處使用的是【伺服器快速部署】
一、安裝Halo
1、安裝Halo
在終端輸入以下指令進行安裝,安裝過程中的設定都走預設即可
yum install -y wget && wget -O halo-cli.sh https://git.io/fxHqp && bash halo-cli.sh -i
2、啟動Halo
在終端輸入以下指令即可啟動Halo
systemctl start halo
在終端輸入以下指令即可将Halo程式加入開機自啟
systemctl enable halo
3、修改端口(可選)
修改 /www/wwwroot/halo/resources 下的application.yaml檔案的port字段值,然後執行下面指令重新開機Halo即可。(此處我修改為了6666)
systemctl restart halo
4、配置Halo
輸入伺服器ip加端口即可開始配置Halo,如果已經設定了域名解析,也可以直接通路域名加端口通路。
二、配置Https
Https證書在騰訊雲或者阿裡雲ssl證書區免費申請即可
1、安裝nginx
在終端輸入以下指令即可安裝nginx
yum install nginx
在終端輸入以下指令即可啟動nginx
systemctl start nginx
在終端輸入以下指令即可将nginx加入開機自啟
systemctl enable nginx
2、修改nginx配置檔案
nginx配置檔案目錄/ect/nginx/nginx.conf,記得把證書的檔案放到指定的目錄
參考下面兩段配置即可(/usr/local/nginx/)。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:6666/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name 127.0.0.1:6666;
root /usr/share/nginx/html;
ssl_certificate "/usr/local/nginx/conf/1_juemuren4449.com_bundle.crt";
ssl_certificate_key "/usr/local/nginx/conf/2_juemuren4449.com.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:6666/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
幾點說明
- 修改配置之後要重新開機nginx或者重新加載配置檔案
- rewrite ^(.*) https://$host$1 permanent;是強制跳轉http到https
- ssl_certificate和ssl_certificate_key對應的是證書檔案的目錄
- 如果使用浏覽器通路https位址後仍然提示不安全,請檢查是否有圖檔或其他資源檔案是非https