首页 > web > nginx

nginx服务器重定向301的正确写法
时间:2016-04-17 01:57:53  点击: 来源:  作者:

把http重定向到https使用了nginx的重定向命令。那么应该如何写重定向?之前老版本的nginx可能使用了以下类似的格式。
rewrite ^/(.*)$ http://domain.com/$1 permanent;
或者
rewrite ^ http://d ...

把http重定向到https使用了nginx的重定向命令。那么应该如何写重定向?之前老版本的nginx可能使用了以下类似的格式。

    rewrite ^/(.*)$ http://domain.com/$1 permanent;


    或者

    rewrite ^ http://domain.com$request_uri? permanent;


现在nginx新版本已经换了种写法,上面这些已经不再推荐。现在网上可能还有很多文章写的是第一种。比如博主的这篇文章《LNMP环境实现301重定向的方法》。

下面是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;

       [....]
}

”您可通过以下微信二维码,赞赏作者“
 
 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
linux服务器同步互联网时间
linux服务器同步互联
亚马逊云lightsail服务器使用教程 | 亚马逊云lightsail使用指南
亚马逊云lightsail服
hostdare 4折优惠,直接降价60% 美国洛杉矶低至 $10.4/年 768M内存/1核/10gNVMe/500g流量
hostdare 4折优惠,直接
六类网线cat6a和cat6e的区别
六类网线cat6a和cat6e
相关文章
栏目更新
栏目热门

关于我们 | 广告服务 | 联系我们 | 网站地图 | 免责声明 | WAP | RSS


Copyright © 运维之家 2013-2023