兩個多月沒寫文章了,也代表兩個多月沒工作了。
掛上cloudflare CDN的網址要強制走https,因為cloudflare到原始伺服器中間的連線是HTTP,所以傳統在nginx上將http 轉成https的作法在chrome上會報錯 ERR_TOO_MANY_REDIRECTS
傳統nginx設法:
server {
listen 80;
server_name my.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name my.domain.com;
# add Strict-Transport-Security to prevent man in the middle attacks
add_header Strict-Transport-Security "max-age=31536000";
[....]
}
解法:
必須在cloudflare後台Page Rules 新增規則
將 http://your.domain.com/* 增加規則 Always Use HTTPS
wordpress用HTTPS訪問,chrome會造成css, js mixed-content錯誤,因為只有主頁走https,其他css, js, 圖片檔案還是走http
解法:
wordpress 後台安裝 HTTP / HTTPS Remover 外掛,並啟用。即可
BUG:
wordpress 後台安裝 CloudFlare Flexible SSL 外掛
最後即可用https訪問掛在cloudflare上的wordpress
參考資料:
http://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?
http://serverfault.com/questions/653976/redirect-loop-using-cloudflares-flexible-ssl Redirect loop using cloudflare's Flexible ssl
沒有留言:
張貼留言