Take notes with follow-up verification, then add 1, 2, 3 steps.
First, install Lua
Second, installation GraphicsMagick
Third, install Nginx
Four, configuration Nginx
Nginx.conf
http {lua_package_path'/usr/local/openresty/nginx/lua/?. LUA;;'; server {Listen the; server_name img.rhythmk.org; Root/home/wwwroot/Static/image; #对类似_100x100. gif/jpg/png/JPEG thumbnail processing location~* _([0-9]+) x ([0-9]+)\. (gif|jpg|png|jpeg) $ {#匹配文件名规则 root/home/wwwroot/Static/image; #站点根目录Set$image _root/home/wwwroot/Static/image; #图片目录Set$thumbnail _root/home/wwwroot/Static/thumbnail; #缩略图存放目录 #如果缩略图文件存在, return directlySet$file $thumbnail _root$uri; if(-f $file) {Rewrite^/(. *) $/thumbnail/$1Last ; } #如果缩略图文件不存在, the thumbnail module is used to processif(!-f $file) {Rewrite_by_lua_file Lua/Thumbnail.lua; }}} #include conf/*. conf;}
Lua/thumbnail.lua
Local index =string. Find (Ngx.var. Uri,"([0-9]+) x ([0-9]+)"); Local Originaluri=string. Sub (ngx.var. Uri,0, index-2); Local Area=string. Sub (ngx.var. Uri, index); Index=string. Find (area,"([.])"); Area=string. Sub (area,0, index-1); Local image_sizes= {"80x80","800x600","40x40"}; function table.contains (table, Element) for_, ValueinchPairs (table) Do ifValue = =element Thenreturn trueEnd Endreturn falseEndiftable.contains (image_sizes, area) then local command="GM Convert".. Ngx.var. Image_root. Originaluri."-thumbnail".. Area.."-background gray-gravity center-extent".. Area.." ".. Ngx.var. File; Os.execute (command); Ngx.req.set_uri (NGX.var. Uri,true); ElseNgx.exit (404); End
Nginx+lua_nginx+graphicsmagick generating real-time thumbnail images