domain.com/custom/url/luboe_nazvanie_pic12975_etc.jpg
/img/12975.jpg
if ($uri ~ pic(\d+)) {
set $pic_id $1;
}
location /custom/url {
root /img;
access_log off;
autoindex off;
expires 30d;
add_header Cache-Control "public, no-transform";
}