個人網站上搭建了有Blog、Git等服務,均是通過nginx反代,以子目錄形式提供服務。因此這些服務是可以共用一個https證書的。
而cloudreve就麻煩了,目前沒有找到以子目錄形式提供服務的辦法,只能先以子域名的方式搭建。
證書的申請也得添加一個子域名證書,好在acme.sh申請Let's Encrypt時,支持多域名證書。
申請了Let's Encrypt後,關鍵是後續要定時更新,而cloudreve服務也不能停,因此只能在nginx的配置上想辦法了。
如下是cloudreve在nginx的反代配置,應該支持同時運行cloudreve服務、證書在後臺自動續期。
server {
listen 80;
listen [::]:80;
server_name cloudreve.XXX.cn;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name cloudreve.XXX.cn;
include /YYY/etc/nginx/sites-conf/https.conf;
include /YYY/etc/nginx/sites-conf/common.conf;
# 支持Let's Encrypt申請證書
location ^~ /.well-known {
# 使用與主網站一樣的路徑
root /YYY/web;
location /.well-known/acme-challenge { try_files $uri $uri/ =404; }
location /.well-known/pki-validation { try_files $uri $uri/ =404; }
return 404;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:5212;
# 如果您要使用本地存儲策略,請將下一行註釋符刪除,並更改大小爲理論最大文件尺寸
# client_max_body_size 20000m;
}
}