如何在nginx

时间:2018-07-26 13:17:02

标签: nginx

我遇到的情况是,我的常规Web应用程序和API在单个服务器上提供。那是 abc.xyz.com

现在,我开发了一个单独的应用程序,该应用程序首先用于移动设备。因此,我将其部署在了mabc.xyz.com上。但是,此移动优先网站访问API使用的是abc.xyz.com。

现在,如果用户从任何移动设备访问abc.xyz.com,我将使用以下配置根据设备类型将其重定向到mabc.xyz.com。

  #----- redirect to mobile check (starts) -----#
  set $mobile_rewrite do_not_perform;

  if ($http_user_agent ~* "android|ip(ad|hone|od)|kindle") {
    set $mobile_rewrite perform;
  }

  if ($mobile_rewrite = perform) {
    rewrite ^ http://mabc.xyz.com redirect;
    break;
  }

配置效果很好,但是当移动优先应用尝试访问abc.xyz.com的API时,由于上述代码,该重定向也会被重定向。

那么在这里如何避免API调用被重定向?

我尝试了以下代码,但效果不佳。

  #----- redirect to mobile check (starts) -----#
  set $mobile_rewrite do_not_perform;

  if ($http_user_agent ~* "android|ip(ad|hone|od)|kindle") {
    set $mobile_rewrite perform;
  }

  #if ($http_accept ~* "json|idjson") {
  #  set $mobile_rewrite do_not_perform;
  #}

  if ($http_content_type  ~* "json|idjson") {
    set $mobile_rewrite do_not_perform;
  }

  if ($mobile_rewrite = perform) {
    rewrite ^ http://mabc.xyz.com redirect;
    break;
  }

上面的conf中缺少什么吗?

0 个答案:

没有答案