Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove query string in Nginx proxy_pass

Tags:

nginx

Is it possible to remove query strings using proxy_pass in Nginx? For example i call my nginx on:

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

And would like to proxy this to:

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

Without the query string "session=123".

Currently my setup just adds any query string i pass to the proxy_pass URL.

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;
}
like image 313
mysanders Avatar asked Sep 21 '15 14:09

mysanders


1 Answers

If you're looking to remove any query string specified on /api/v2/logout, adding set $args ""; should work:

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;
}
like image 160
Jonathan Avatar answered Oct 16 '22 16:10

Jonathan