Nginx - encoding (normalizing) part of URI -


i have nginx location directive purpose "remove" localization prefix uri proxy_pass directive.

for example, make uri http://example.com/en/lalala use proxy_pass http://example.com/lalala

location ~ '^/(?<locale>[\w]{2})(/(?<rest>.*))?$' {         ...         proxy_pass http://example/$rest;         ... } 

this way rest variable decoded when passed proxy_pass directeve. seems expected behavior.

the problem when uri contains encoded space %20 passed client

http://example.com/lala%20lala 

nginx decodes uri to

http://example.com/lala lala 

i can see in error.log.

the question - possible use encoded rest variable somehow passed client? if doing wrong, please, suggest right way.

thank you.

yes, behaviour expected although docs say:

if proxy_pass specified without uri, request uri passed server in same form sent client when original request processed, or full normalized request uri passed when processing changed uri:

location /some/path/ {     proxy_pass http://127.0.0.1; } 

nginx engineers same: https://serverfault.com/questions/459369/disabling-url-decoding-in-nginx-proxy

however if append $request_uri proxy_pass (and strip locale beforehand may work said nginx engineer):

set $modified_uri $request_uri;  if ($modified_uri ~ "^/([\w]{2})(/.*)") { set $modified_uri $1; }  proxy_pass http://example$modified_uri; 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -