8

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;
}
0

2 Answers 2

6

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This did nothing for me with nginx 1.20.1 -- the answer from @Thierry worked though
1

I believe you could do it with a rewrite rule like:

rewrite ^(.*)$ $1?;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.