<div dir="ltr"><span style="font-size:12.8px;font-variant-ligatures:normal">Greetings Nginx mailing list!</span><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">I'm using nginx as an image proxy and am using proxy_pass to fetch the image. Unfortunately if that image URL has a space in it the proxy_pass fails. It works fine with any other image.</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">example successful URL:</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">/image_preview/<a href="https://somedomain.com/image.jpg" target="_blank">https://somedom<wbr>ain.com/image.jpg</a></div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal"><div style="font-size:small">example failedl URL:</div><br class="gmail-m_2039883881470043549gmail-m_-6818797042467442952gmail-m_830913135982155706gmail-m_-4291920481501457916gmail-m_7497130035442823834gmail-m_-3591132416970481713gmail-m_4882708909491858236gmail-m_1652576504091731899gmail-Apple-interchange-newline"><div style="font-size:small">/image_preview/<a href="https://somedomain.com/My%20Images/image.jpg" target="_blank">https://somedom<wbr>ain.com/My%20Images/image.jpg</a></div><div style="font-size:small"><br></div><div style="font-size:small">^^</div><div style="font-size:small">Nginx is URL decoding the url in the path and putting the space back in.</div><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">Here's my nginx.conf</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal"><div>        # redirect thumbnail url to real world</div><div>        location ~ ^/image_preview/(.*?)$  {</div><div>            resolver ${HOST};</div><div><br></div><div>            set $fallback_image_url ${FALLBACK_IMAGE_URL};</div><div>            set $image_url $1;</div><div><br></div><div>            if ($args) {</div><div>                set $image_url $1?$args;</div><div>            }</div><div><br></div><div>            proxy_intercept_errors on;</div><div>            error_page 301 302 303 305 306 307 308 $fallback_image_url;</div><div>            error_page 400 401 402 403 404 405 406 409 408 409 410 411 412 413 414 415 416 417 $fallback_image_url;</div><div>            error_page 500 501 502 503 504 505 506 507 508 509 510 511 520 522 598 599 $fallback_image_url;</div><div><br></div><div>            proxy_connect_timeout 2s;</div><div>            proxy_read_timeout 4s;</div><div>            proxy_pass_request_headers off;</div><div>            proxy_buffering off;</div><div>            proxy_redirect off;</div><div><br></div><div>            proxy_pass $image_url;</div><div>            proxy_set_header If-None-Match $http_if_none_match;</div><div>            proxy_set_header If-Modified-Since $http_if_modified_since;</div><div>        }</div></div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">I've scoured the docs, stackoverflow, and the internet in general but don't see how to address this problem. As I see it I have two options:</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">1) Find a way to make nginx not URL decode the param URL (doesn't seem possible)</div><div style="font-size:12.8px;font-variant-ligatures:normal">2) The original $request_uri contains the URL encoded URL. Find a way to create a rewrite rule to strip off the prefix and proxy_pass to the resulting URL. I haven't found a way to do something liek that as it appears rewrite rules will only operate on the URI in context and that URI appears to be decoded.</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">I've found an entire chapter in "Nginx Troubleshooting" on creating a proxy for external links. But that example also appears to fall vicitm to this same problem.</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">Any help/pointers would be appreciated as I am pretty well stuck at this point on an  approach that might work.</div><div style="font-size:12.8px;font-variant-ligatures:normal"><br></div><div style="font-size:12.8px;font-variant-ligatures:normal">Thanks,</div><div class="gmail_signature"><div dir="ltr">-Michael<br></div></div>
</div>