6

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,432
  • 6
  • 55
  • 88
Ram Iyer
  • 1,404
  • 2
  • 20
  • 27

2 Answers2

5

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
  • 499
  • 4
  • 12
2

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
  • 12,413
  • 5
  • 52
  • 67