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

不能放到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;
}

posted @ 2021-08-31 18:07  风儿飘  阅读(242)  评论(0编辑  收藏  举报