详解nginx服务器http重定向到https的正确写法
author:一佰互联 2019-04-23   click:151

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;  [....]}

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