1

I to proxy /api on a domain, I have this location block.

location ^~ /api/ {
    rewrite_log on;
    rewrite ^/api/(.*) /$1$is_args$args break;
    proxy_pass http://127.0.0.1:1337;
}

It works fine as long as the URLs do not have query parameters, but as soon as they do, I get errors on the upstream server like these Could not find path: /records%3fname=hoegh.io

The %3f in question here is an URL encoded ?, and since it's URL encoded, the upstream server does not recognize it. That might be retarded, but I was hoping it was possible to get nginx to handle this correctly (ie. not escape the URL before passing it to the proxy).

Any ideas?

2
  • Did the solution provided work for you? Please accept the answer Commented Nov 27, 2013 at 19:54
  • "retarded" is an unfortunate and derogatory choice of word here. Commented Nov 7, 2018 at 0:29

2 Answers 2

1

You don't need to do anything. $args is passed along automatically.

If you wish to modify the $args that are passed you have to override.

set $args "foo=bar";

for instance.

Working solution should go as follows:

location ^~ /api/ {
    rewrite_log on;
    rewrite ^/api/(.*) /$1 break;
    proxy_pass http://127.0.0.1:1337;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried this instead? It's generally not needed to add the query string as Nginx adds it automatically:

rewrite ^/api/(.*) /$1? break;

2 Comments

I did have that earlier, but then it seemed the query string wasn't passed along at all.
Sorry, my bad. I forgot to type the ? at the end of the redirect string

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.