nginx服務器http重定向到https的正確寫法


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;

    [....]
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM