如何重寫url以使用www和https所有的時間?nginx:如何重寫url以使用www和https
// The url can have https but not www
https://example.com
// The url can have www but not https
http://www.example.com
// The url can have neither https, neither www
http://example.com
=> rewrite to https://www.example.com
我已經使用以下方式將https添加到所有請求中,但http又怎麼樣?有沒有一種有效的方式來添加它?
server {
listen 80;
listen [::]:80;
return 301 https://$host$request_uri;
}
由於
這似乎是合乎邏輯的,但我有一些問題,所以我只用一個服務器塊,最後一個443 SSL和www.domain.com嘗試。 當我只有這樣的時候,「https:// www.domain.com」和「https:// domain.com」都可以工作。這就像nginx忽略server_name?我沒有想到'https:// domain.com'在這種情況下工作,對嗎? – Michael 2014-10-29 13:59:16