How to perform division operation on variables in nginx?
怪我咯
怪我咯 2017-05-16 17:30:00
0
1
697

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?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
伊谢尔伦

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....

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!