千家信息网

详解nginx服务器http重定向到https的正确写法

发表于:2024-10-26 作者:千家信息网编辑
千家信息网最后更新 2024年10月26日,http重定向到https使用了nginx的重定向命令。那么应该如何写重定向?之前老版本的nginx可能使用了以下类似的格式。rewrite ^/(.*)$ http://domain.com/$1
千家信息网最后更新 2024年10月26日详解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;  [....]}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

0