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