5

It seems Nginx it always un-encodes urls when used with a regular expression. I have a rewrite rule:

location /api/ {
    rewrite /api/(.*)$ $1 break;
    proxy_pass http://127.0.0.1:8000/$1;
}

I would like to remove the api from the usl but keep the rest of the path. Part of the path is an email address someone@somewhere.com. I am passing someone%40somewhere.com but Nginx is turning it back with the @ sign.

Matthias
  • 7,322
  • 6
  • 55
  • 86
Ram Iyer
  • 1,325
  • 2
  • 19
  • 27

2 Answers2

4

The correct answer seem to be

location /api/ {
        rewrite ^ $request_uri;
        rewrite ^/api/(.*) $1 break;
        return 400;
        proxy_pass http://127.0.0.1:8000/$uri;
    }

See Nginx pass_proxy subdirectory without url decoding for full answer and original author.

(I realize this question is older than the one I referenced but I found this in google search and may not be the last one, so ...)

Honza
  • 441
  • 2
  • 10
1

That is how Nginx handles urls. You can bypass it by changing your web application to escape the "%" character as "%25" and pass someone%2540somewhere.com.

This will be unescaped as someone%40somewhere.com.

Dayo
  • 11,753
  • 5
  • 48
  • 65