首页 > 其他 > 详细

nginx 同一个域名下分终端重定向

时间:2021-09-02 06:06:07      阅读:11      评论:0      收藏:0      [点我收藏+]

不能放到location外(全局),会造成重定向死循环

放到location内,因为是同一域名会造成部分uri一起重定向造成页面显示不正常。

加了访问绝对路径 /  

同时判断user_agent 为手机 才重定向

第二个location 也是为了死循环
location / {
  set $a 1;
  set $b 2;

  if ($request_uri ~* "^/$") {
    set $a 0;
  }
  if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
    set $b 0;
  }
   if ($a = $b) {
    rewrite ^/(.*)$ https://aaa.test.duia.com/wap/g-p/employment/$1 permanent;
  }  

  proxy_pass http://aaa.test.duia.com;
}

location /wap/g-p/employment {
proxy_pass http://aaaa.test.duia.com;
}

 

不同域名:

if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
  rewrite ^/(.*)$ https://bbb.test.duia.com/wap/g-p/employment/$1 permanent;
}

nginx 同一个域名下分终端重定向

原文:https://www.cnblogs.com/sqbk/p/15211614.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!