export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0/
./configure --prefix=/usr/local/tengine-2.1.0 --dso-path=/usr/local/tengine-2.1.0/modules --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_concat_module --with-http_lua_module --http-proxy-temp-path=/var/tmp/tengine-2.1.0/proxy_temp --http-fastcgi-temp-path=/var/tmp/tengine-2.1.0/fastcgi_temp --http-uwsgi-temp-path=/var/tmp/tengine-2.1.0/uwsgi_temp --http-scgi-temp-path=/var/tmp/tengine-2.1.0/cgi_temp --http-client-body-temp-path=/var/tmp/tengine-2.1.0/client_body_temp --http-log-path=/var/log/tengine-2.1.0/access.log --error-log-path=/var/log/tengine-2.1.0/error.log --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
742 yum install freetype
743 yum install freetype-devel
744 ./configure --prefix=/usr/local/GraphicsMagick-1.3.20 --enable-shared
745 make
746 make install
location ~* ^(.+\.(jpg|jpeg|gif|png))_(\d+)_(\d+)\.(jpg|jpeg|gif|png)$ {
root /data1/wwwroot/img.yuanfenba.net/;
if (!-f $request_filename) {
#content_type ‘text/plain‘;
#content_by_lua ‘ngx.say("hello, lua")‘;
#add_header X-Powered-By ‘Lua GraphicsMagick‘; # 此 HTTP Header 无实际意义,用于测试
#add_header file-path $request_filename; # 此 HTTP Header 无实际意义,用于测试
#lua_code_cache off; # 在编写外部 Lua 脚本时,设置为 off Nginx 不会缓存 Lua,方便调试
set $request_filepath $document_root$1;
set $big_pic_url $1;
set $width $3;
set $height $4;
set $ext $5;
content_by_lua_file /document_root/ImageResizer.lua;
}
}
ImageResizer.lua
#!/usr/bin/env lua
function file_exists(name)
local f=io.open(name,"r");
if f~=nil then io.close(f) return true else return false end;
end
if not file_exists("/www/img.yuanfenba.net".. ngx.var.big_pic_url) then
command = string.format("wget -m -P /www/ http://img.yuanfenba.net/"..ngx.var.big_pic_url);
os.execute(command);
-- ngx.say(command)
end
if ngx.var.width == "540" then chuli = "crop" else chuli = "resize" end
local command = "/usr/local/GraphicsMagick-1.3.20/bin/gm convert " .. ngx.var.request_filepath .. " -" ..chuli.." " .. ngx.var.width .. "x" .. ngx.var.height .. "! +profile \"*\" " .. ngx.var.request_filepath .. "_" .. ngx.var.width .. "_" .. ngx.var.height .. "." .. ngx.var.ext;
--ngx.say(command);
os.execute(command);
return ngx.redirect(ngx.var.request_uri, ngx.HTTP_MOVED_TEMPORARILY)