删除Nginx proxy_pass中的查询字符串

时间:2015-09-21 14:39:30

标签: nginx

是否可以在Nginx中使用proxy_pass删除查询字符串? 例如,我打电话给我的nginx:

http://nginxproxy.com/api/v1/logout?session=123

并希望将此代理:

http://example.com/api/sessions/?_action=logout

没有查询字符串“session = 123”。

目前我的设置只是添加了传递给proxy_pass网址的任何查询字符串。

location /api/v2/logout {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Session $arg_token;
        proxy_pass http://example.com/api/sessions/?_action=logout;
}

1 个答案:

答案 0 :(得分:0)

如果您要删除在/api/v2/logout上指定的任何查询字符串,则添加set $args "";应该可以:

location /api/v2/logout {
    set $args "";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Session $arg_token;
    proxy_pass http://example.com/api/sessions/?_action=logout;
}