2015-11-04 33 views
0

我想爲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; 
    } 
} 

回答

0

固定通過添加2行:

proxy_redirect https://example.github.io https://example.com; 
proxy_redirect http://example.github.io https://example.com; 

而且順便說一句,如果您想在Github Pages上託管Jekyll/Ghost,請確保您的帖子的永久鏈接以/結尾,否則它將花費一分錢諾特爾301 ..

添加服務器端推動的CSS文件,如果使用化身,在server塊:

add_header Link '</css/main.css>; rel=preload; as=stylesheet'; 
相關問題