我想爲Github頁面使用自定義域,並使用我自己的證書(不是CloudFlare)啓用HTTPS。將nginx設置爲Github頁面前端,啓用https
根據Github的頁面指令,第一部分是通過建立CNAME無論是在項目的根文件夾,DNS進行,但不支持這樣HTTPS:https://example.github.io
自定義域example.com
僅在http://example.com
訪問,https://example.com
韓元」工作。
因此,我正在考慮nginx反向代理:刪除CNAME文件和DNS設置,讓3個鏈接共存,將http自定義域重定向到https,將https的請求轉發到github.io
地址。
但是,結果並不完美:主頁和css(在/css/main.css!)加載正確,所有鏈接都顯示正常,但點擊它們會導致301並重定向到github.io。
我nginx的版本是1.9.5,對於端口80的配置:
server {
listen 80;
server_name myblog.com;
return 301 https://$server_name$request_uri;
}
爲443:
server {
listen 443 ssl http2;
server_name myblog.com;
ssl_certificate /etc/nginx/ssl/orz.crt;
ssl_certificate_key /etc/nginx/ssl/orz.key;
add_header Strict-Transport-Security max-age=31536000;
location/{
proxy_pass https://example.github.io;
proxy_set_header Host example.github.io;
}
}