条件代理传递而不是重定向

时间:2018-06-01 11:13:20

标签: linux nginx reverse-proxy

需要"重定向"在GET / POST中使用请求参数和请求正文的条件url到anothre域。这就是它现在的工作方式。

   location ~* /aa/.*/bb.json{
                 proxy_pass   http://127.0.0.1:7001;
                 if ($arg_bornEnv = pro ) { rewrite ^.*$ http://pro.xxxx.com$uri last;}
                 if ($arg_bornEnv = pre ) { rewrite ^.*$ http://pre.xxxx$uri last;}
             }

它适用于浏览器,并会使用" 302"将网址重定向到目标位置。码。这意味着它将在url字段中更改url。我想在一个请求中完成此抛出代码,例如,httpclient等。

这可以通过条件代理传递完成吗?

2 个答案:

答案 0 :(得分:0)

location ~* /aa/.*/bb.json{
   if ($arg_bornEnv = pro ) { rewrite ^.*$ http://pro.xxxx/$1 redirect;}
   if ($arg_bornEnv = pre ) { rewrite ^.*$ http://pre.xxxx/$1 redirect;}
   proxy_pass   http://127.0.0.1:7001;
}

答案 1 :(得分:0)

location ~* /aa/.*/bb.json {
             if ($arg_bornEnv = pro ) { proxy_pass http://pro.xxxx;}
             if ($arg_bornEnv = pre ) { proxy_pass http://pre.xxxx;}

             proxy_pass   http://127.0.0.1:7001;
         }

这就是现在的工作方式。