Nginx设置301域名跳转总结 – 21运维
通知: .-...

Nginx设置301域名跳转总结

linux系统基础 21运维 5211浏览 0评论

域名301跳转这个经常用到,之前单独写过一个文章《nginx 如何设置将http自动跳转到https》,这个太不完善了,这里再记录下更为通用的方式实现301域名跳转。

1,rewrite方式。
比如之前写的http跳转到https就是这样实现的:

listen 80;
server_name download.21yunwei.com test.21yunwei.com;
rewrite ^(.*) https://download.21yunwei.com$1 permanent;

2,return方式。

server_name www.21yunwei.com;
return 301 https://$host$request_uri;

3,添加判断代码。

                if ($host !~* "^download.21yunwei.com$"){
                    rewrite ^(.*) https://download.21yunwei.com$1;
                    break;
                }

4,文件加入跳转代码实现。

站点根目录下设置一个index.html,里边设置代码:

<html>  
<meta http-equiv="refresh" content="0;url=https://download.21yunwei.com/"/>  
</html>  

转载请注明:21运维 » Nginx设置301域名跳转总结

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址