西数超哥博客
运维经验教程分享

Nginx设置301域名跳转总结

域名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>  

转载请注明:西数超哥博客www.ysidc.top» Nginx设置301域名跳转总结

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0)
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥博客 » Nginx设置301域名跳转总结