Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx rewrite unencodes url

Tags:

nginx

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 [email protected]. I am passing someone%40somewhere.com but Nginx is turning it back with the @ sign.

like image 818
Ram Iyer Avatar asked Oct 09 '22 01:10

Ram Iyer


1 Answers

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 ...)

like image 186
Honza Avatar answered Oct 13 '22 12:10

Honza