server {
...
index index.php;
...
location ~ ^.*\.php
{
...
}
root /path/to/your/static/files/;
}
function err_handle {
status=$?
if [[ $status -ne 127 ]]; then
return
fi
lastcmd=$(history | tail -1 | sed 's/^ *[0-9]* *//')
read cmd args <<< "$lastcmd"
possible_cmd=$(ls /sbin/${cmd}* /bin/${cmd}* /usr/bin/${cmd}* /usr/local/bin/${cmd}* 2>/dev/null)
echo "Sorry, $cmd doesn't exist. Try $possible_cmd"
}
trap 'err_handle' ERR
http {
perl_require myhandler.pm;
...
server {
...
location ~* /original/\.(gif|jpg|png)$ {
perl myhandler::handler;
}
}
}
package myhandler;
use nginx;
use Digest::MD5 qw(md5_hex);
sub handler {
my $r = shift;
if ($r->filename=~m|/original/(.*?)\.(jpg|gif|png)|) {
my $id_md5=md5_hex($1);
my $filename="/original/".substr($id_md5,31,1)."/".substr($id_md5,0,2)."/".substr($id_md5,2,2).".".$2;
$r->sendfile($filename);
}
return OK;
}
1;
__END__