I am using nginx’s Proxy module to retrieve images from Amazon S3. I
need to
be able to tell the Proxy module to retrieve a smaller sized file if a
bigger sized file doesnt exist. How can I do that?
If you want rewrite from /something_300.jpg to /something_100.jpg
to happen automatically, for all possible values of “something”,
then config like this should work, using named location and
rewrite:
location / {
error_page 404 = @fallback;
proxy_pass http://upstream;
proxy_intercept_errors on;
}
location @fallback {
# if request ends with _300.jpg - rewrite to _100.jpg
# and stop processing of rewrite rules, i.e. continue
# with proxy_pass; else return 404
rewrite ^(.*)_300.jpg$ $1_100.jpg break;
return 404;
proxy_pass http://upstream;
}