The question is quite vague, but, based on the error message, what you're trying to do is perform a proxy_pass
entirely based on the user input, by using the complete URL specified after the /image/
prefix of the URI.
Basically, this is a very bad idea, as you're opening yourself to become an open proxy. However, the reason it doesn't work as in the conf you supplied is due to URL normalisation, which, in your case, compacts http://example
into http:/example
(double slash becomes single), which is different in the context of proxy_pass
.
If you don't care about security, you can just change merge_slashes
from the default of on
to off
:
merge_slashes off;
location …
Another possibility is to somewhat related to nginx proxy_pass and URL decoding
location ~ ^/image/.+ {
rewrite ^ $request_uri;
rewrite ^/image/(.*) $1 break;
return 400;
proxy_pass $uri; # will result in an open-proxy, don't try at home
}
The proper solution would be to implement a whitelist, possibly with the help of map
or even prefix-based location directives:
location ~ ^/image/(http):/(upload.example.org)/(.*) {
proxy_pass $1://$2/$3;
}
Do note that, as per the explanation in the begginning, the location above is subject to the merge_slash
setting, so, it'll never have the double //
by default, hence the need to add the double //
manually at the proxy_pass
stage.