Trying to convert over an apache config to nginx.
<Directory /usr/local/image/>
Order allow,deny
Allow from all
</Directory>
Alias /key1 /usr/local/image
Alias /key2 /usr/local/image
RewriteEngine On
RewriteCond /usr/local/image/$1 !-f
RewriteRule ^\.(jpg|jpeg|gif|png))$ /handler.php
so a request to /key1/subdir1/subdir2/123.png OR /key2/subdir1/subdir2/123.png would look to /usr/local/image/subdir1/subdir2/123.png, serve it if it exists, or go to /handler.php if not (404)
I've tried:
location ^~ /key1 {
alias /usr/local/image/;
error_page 404 /handler.php;
}
Which somewhat works - but I would like to limit this rule to only images (jp?g|gif|png) but the subdir1 & subdir2 values will vary.
Any suggestions on how to efficiently do this in nginx?