Answer the question
In order to leave comments, you need to log in
nginx config how?
Hello.
We need to make a location rule, but I'm not familiar with nginx / perl.
When accessing /original/$ID. jpg|png|gif
It is necessary that the image be returned along the path
original/
the last character md5($ID) /
the first 2 characters md5($ID) /
3rd and 4th character md5($ID). jpg|png|gif
Answer the question
In order to leave comments, you need to log in
wiki.nginx.org/EmbeddedPerlModule
Something like this (didn't test it, but it should seem to work):
nginx.conf:
http { perl_require myhandler.pm; ... server { ... location ~* /original/\.(gif|jpg|png)$ { perl myhandler::handler; } } }
packagemyhandler; 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; } one; __END__
Put this logic into a script, and then serve the image through internal redirects .
The function of calculating MD5 in the nginx config is only in ephemeral plans ... but for now it is impossible to calculate MD5 from something (without a third-party module).
It’s a completely different matter if suddenly $ID itself turns out to be an MD5 sum ...
Then (the code was not tested):
location /original/ {
rewrite ^/original/([0-9a-f][0-9a-f])([0- 9a-f]+)([0-9a-f])\. (jpg|png|gif)$ /original/$3/$1/$1$2$3.$4 last;
}
Read the documentation for more details:
sysoev.ru/nginx/docs/http/ngx_http_rewrite_module.html
Maybe this will help something: sysoev.ru/nginx/docs/http/ngx_http_secure_link_module.html
IMHO, you can't do this in nginx, you need to do something differently
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question