Rewrite Rule Guide
[ 268 ]# note the quotes around the regular expression - these
are
# required because we used {} within the expression
itself
rewrite '^/images/([a-z]{2})/([a-z0-9]{5})/(.*)\.
(png|jpg|gif)$' /data?file=$3.$4;# note that we didn't use the 'last' parameter above; if
we had,
# the variables below would not be set because NGINX
would
# have ended rewrite module processing# here we set the variables that are used in the custom
log
# format 'imagelog'
set $image_file $3;set $image_type $4;}location /data {# we want to log all images to this specially-formatted
logfile
# to make parsing the type and size easier
access_log logs/images.log imagelog;root /data/images;# we could also have used the $image-variables we defined
# earlier, but referencing the argument is more readable
try_files /$arg_file /image404.html;}location = /image404.html {# our special error message for images that don't exist
return 404 "image not found\n";}}