nginx转发get请求丢失参数

时间:2025-03-18 09:43:27

场景:

用nginx转发请求时,需要剥离某些字段。

如:

http://127.0.0.1/myname/api/baseinfo/getlist?class=1

需要将请求设置为:

http://127.0.0.1:8080/api/baseinfo/getlist?class=1

一开始的location配置为:

location ~ /myname/(.*) {
    proxy_pass $scheme://127.0.0.1:8080/$1;
}

但是发现 ? 后面的请求参数没有被转发,修改后的location配置如下:

location ~ /myname/(.*)$ {
    proxy_pass $scheme://127.0.0.1:8080/$1?$args;
}

问题解决!

 

参考文章:

nginx正则捕获get请求参数丢失的解决