proxy_pass and trailing / decode uri
Maxim Dounin
mdounin at mdounin.ru
Sun Mar 11 22:26:47 UTC 2018
Hello!
On Thu, Mar 08, 2018 at 10:34:36PM +0100, max wrote:
> Sorry if it was already asked but I'd like to know if the only way to
> prevent Nginx from decoding uri while using proxy_pass is:
> https://stackoverflow.com/a/37584656/3515745
>
> Here is my (simplified) conf:
>
> server {
> server_name domain1.com;
>
> location / {
> proxy_pass http://127.0.0.1:81;
>
> }
>
> location /api {
> proxy_pass http://127.0.0.1:82/;
>
> }
> }
>
> Location "/" is perfectly working. My problem is that "/api" location will
> decode special character.
When you want nginx to replace matching part of the URI with "/",
it will do so on the decoded/normalized URI, and will re-encode
special characters in what's left.
If you want nginx to preserve original URI as sent by the client,
consider using proxy_pass without the URI part. That is,
instead of
proxy_pass http://127.0.0.1:82/;
use
proxy_pass http://127.0.0.1:82;
Note no trailing "/". This way the original URI as sent by the
client will be preserved without any modifications.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list