For example, the requested url is
photos/100000_0_9-.jpg
I want to calculate the number 100000 and divide it
location ~ /photos/([0-9]+)_0_([0-9]+)-.jpg$ { root '/home/images'; set $id /10000; set $version ; rewrite /photos/([0-9]+)_0_([0-9]+)-.jpg$ /$id/$version/_0_-.jpg; }
Then rewrite to the directory corresponding to the id, but if you do this, the value of id will become 100000/10000 instead of 10.
How to implement this division operation in nginx?
伊谢尔伦2017-05-16 17:32:00
The Nginx configuration file does not seem to support data science operations. You can use the HttpLuaModule written by agentzh.
location ~ /photos/([0-9]+)_0_([0-9]+)-.jpg$ { root '/home/images'; set $id ; set $version ; set_by_lua $id "return math.floor(tonumber(ngx.arg[1])/10000)" $id; rewrite /photos/([0-9]+)_0_([0-9]+)-.jpg$ /$id/$version/_0_-.jpg; }
You can also write a simple mathematical operation extension in bytes https://github.com/arut/nginx-let-mod....