Disabling URL decoding in nginx proxy

Posted by Tomasz Nurkiewicz on Server Fault See other posts from Server Fault or by Tomasz Nurkiewicz
Published on 2012-12-19T15:56:22Z Indexed on 2012/12/19 17:04 UTC
Read the original article Hit count: 324

Filed under:
|
|

When I browse to this URL: http://localhost:8080/foo/%5B-%5D server (nc -l 8080) receives it as-is:

GET /foo/%5B-%5D HTTP/1.1

However when I proxy this application via nginx:

location /foo {
        proxy_pass    http://localhost:8080/foo;
}

The same request routed through nginx port is forwarded with path decoded:

GET /foo/[-] HTTP/1.1

Decoded square brackets in the GET path are causing the errors in the target server (HTTP Status 400 - Illegal character in path...) as they arrive un-escaped.

Is there a way to disable URL decoding or encode it back so that the target server gets the exact same path when routed through nginx? Some clever URL rewrite rule?

© Server Fault or respective owner

Related posts about nginx

Related posts about rewrite