http重定向到https使用了nginx的重定向命令。那么應該如何寫重定向?之前老版本的nginx可能使用了以下類似的格式
rewrite ^/(.*)$ http://domain.com/$1 permanent;
或者
rewrite ^ http://domain.com$request_uri? permanent;
現在nginx新版本已經換了種寫法,上面這些已經不再推薦。
下面是nginx http頁面重定向到https頁面最新支持的寫法:
server { listen 80; server_name my.domain.com; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name my.domain.com; [....] }