Nginx 中 location是不支持 URL参数 配置的,若要识别相关URL参数并作处理,需要使用$query_string变量及if 指令。
如下,当匹配 /test 时,若 /test?type=1 为真,则使用http://172.16.253.229:7300代理该请求,即 http://mock-oint.61info.cn/test?type=1 ==> http://172.16.253.229:7300/test?type=1。
server {
listen 80;
server_name mock-oint.61info.cn;
access_log logs/mock.log;
error_log logs/mock_error.log;
location /test {
// 当携带相关参数时,代理到其他服务
if ($query_string = 'type=1') {
proxy_pass http://172.16.253.229:7300;
break;
}
proxy_pass http://172.16.253.229:7301;
}
}