GraphicsMagickhtml
A:\>gm convert 12.png -thumbnail 100x100^ -gravity center -extent 100x100 -quality50 output_4.jpg
wget http://luajit.org/download/LuaJIT-2.0.0-beta10.tar.gz tar vxzf LuaJIT-2.0.0-beta10.tar.gz cd LuaJIT-2.0.0-beta10 make&&makeinstallPREFIX=/usr/local/lj2 ln-sf luajit-2.0.0-beta10 /usr/local/lj2/bin/luajit #下載最新的 ngx_devel_kit (NDK) 模塊cd/tmp/wget http://github.com/simpl/ngx_devel_kit/tarball/v0.2.17rc2 tar vxzf v0.2.17rc2 ls simpl-ngx_devel_kit-bc97eea #下載最新的lua-nginx-module 模塊wget http://github.com/chaoslawful/lua-nginx-module/zipball/v0.5.8rc1 unzip v0.5.8rc1 ls chaoslawful-lua-nginx-module-a624ee9 cd/tmp wget'http://nginx.org/download/nginx-1.0.10.tar.gz'tar-xzvf nginx-1.0.10.tar.gz cd nginx-1.0.10/# 或者設置 LuaJIT 環境變量exportLUAJIT_LIB=/usr/local/lj2/lib exportLUAJIT_INC=/usr/local/lj2/include/luajit-2.0# 這裏假設 Nginx 安裝路徑是 /usr/local/nginx/#./configure --prefix=/usr/local/nginx \--add-module=/tmp/simpl-ngx_devel_kit-bc97eea \--add-module=/tmp/chaoslawful-lua-nginx-module-a624ee9 #./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module \--add-module=/tmp/simpl-ngx_devel_kit-bc97eea \--add-module=/tmp/chaoslawful-lua-nginx-module-a624ee9 #2表明cpu核數make-j4makeinstall[root@ghost-rider lib]# /etc/init.d/nginx restart Restarting nginx daemon: nginxcat: /usr/local/nginx/logs/nginx.pid: No such file or directory kill: usage: kill[-s sigspec |-n signum | -sigspec] pid | jobspec ... or kill-l[sigspec] nginx not running/usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory nginx already running. [root@ghost-rider ~]# ldd /usr/local/nginx/sbin/nginx linux-vdso.so.1 =>(0x00007fffeabff000) libpthread.so.0 =>/lib64/libpthread.so.0 (0x0000003a20600000) libcrypt.so.1 =>/lib64/libcrypt.so.1 (0x0000003a2b600000) libluajit-5.1.so.2 => not found libm.so.6 =>/lib64/libm.so.6 (0x0000003a20a00000) libpcre.so.0 =>/usr/local/lib/libpcre.so.0 (0x00007f4bf0971000) libcrypto.so.10 =>/usr/lib64/libcrypto.so.10 (0x000000301f200000) libz.so.1 =>/lib64/libz.so.1 (0x000000301a200000) libc.so.6 =>/lib64/libc.so.6 (0x0000003a20200000)/lib64/ld-linux-x86-64.so.2 (0x0000003a1fa00000) libfreebl3.so =>/usr/lib64/libfreebl3.so (0x0000003a2de00000) libdl.so.2 =>/lib64/libdl.so.2 (0x0000003a1fe00000)[root@ghost-rider ~]# /lib lib/ lib64/[root@ghost-rider ~]# /lib lib/ lib64/[root@ghost-rider ~]# /lib lib/ lib64/[root@ghost-rider ~]# /lib64/lj^C[root@ghost-rider ~]# cp /usr/local/lj2/lib/l libluajit-5.1.a libluajit-5.1.so libluajit-5.1.so.2 libluajit-5.1.so.2.0.0 lua/[root@ghost-rider ~]# cp /usr/local/lj2/lib/libluajit-5.1.so.2 anaconda-ks.cfg core.1350 .gconfd/ packages/ vhost.sh .bash_history .cshrc .gem/ .pki/ weedfs/ .bash_logout D .gitconfig post-install weedfs.0.14.linux_amd64.tar.gz .bash_profile .dbshell .gitolite/ post-install.log .bashrc fix_volume_index .htoprc .ssh/ ?b. .gconf/ lnmp .tcshrc [root@ghost-rider ~]# cp /usr/local/lj2/lib/libluajit-5.1.so.2 /lib64/[root@ghost-rider ~]# ldd /usr/local/nginx/sbin/nginx linux-vdso.so.1 =>(0x00007fff8d9ff000) libpthread.so.0 =>/lib64/libpthread.so.0 (0x0000003a20600000) libcrypt.so.1 =>/lib64/libcrypt.so.1 (0x0000003a2b600000) libluajit-5.1.so.2 =>/lib64/libluajit-5.1.so.2 (0x00007f0d3bbb4000) libm.so.6 =>/lib64/libm.so.6 (0x0000003a20a00000) libpcre.so.0 =>/usr/local/lib/libpcre.so.0 (0x00007f0d3b999000) libcrypto.so.10 =>/usr/lib64/libcrypto.so.10 (0x000000301f200000) libz.so.1 =>/lib64/libz.so.1 (0x000000301a200000) libc.so.6 =>/lib64/libc.so.6 (0x0000003a20200000)/lib64/ld-linux-x86-64.so.2 (0x0000003a1fa00000) libfreebl3.so =>/usr/lib64/libfreebl3.so (0x0000003a2de00000) libdl.so.2 =>/lib64/libdl.so.2 (0x0000003a1fe00000) libgcc_s.so.1 =>/lib64/libgcc_s.so.1 (0x0000003a2c200000)[root@ghost-rider nginx-1.0.10]# /usr/local/nginx/sbin/nginx -v nginx: nginx version: nginx/1.0.10
或者使用openresty安裝包,集成好了nginx各類組件(仍是換這種靠譜)。前端
yum install readline-devel pcre-devel openssl-devel cd/tmp wget http://agentzh.org/misc/nginx/ngx_openresty-1.0.15.10.tar.gz tar vxzf ngx_openresty-1.0.15.10.tar.gz cd ngx_openresty-1.0.15.10 ./configure --user=www --group=www --prefix=/usr/local/openresty \--with-luajit \ --without-http_redis2_module \ --with-http_iconv_module #若是是多核,假設是4核make-j4makeinstall ce /tmp wget http://downloads.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.16/GraphicsMagick-1.3.16.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fgraphicsmagick%2Ffiles%2Fgraphicsmagick%2F1.3.16%2F&ts=1343298549&use_mirror=cdnetworks-kr-1tar vxzf GraphicsMagick-1.3.16.tar.gz cd GraphicsMagick-1.3.16 ./configure make&&makeinstall
錯誤處理linux
nginx 404 failed (2: No such file or directory) nginx 403 forbidden,檢查nginx啓動用戶是否有對站點目錄的讀和執行權限。nginx.conf第一行,能夠經過設置user www www來指定執行的用戶。
gm convert /home/wwwroot/st.xxx/p_w_picpaths/xxxxx.jpg.80x80.jpg -thumbnail 100x100 -background gray -gravity center -extent 100x100 output.jpg;nginx
http://www.graphicsmagick.org/GraphicsMagick.html#details-thumbnailgit
nginx.con配置github
location /p_w_picpaths/{set$p_w_picpath_root/home/wwwroot/st.xxx; set$file"$p_w_picpath_root$uri"; if(!-f $file){ rewrite_by_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 p_w_picpath_sizes = {"80x80", "800x600", "40x40"}; function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end if table.contains(p_w_picpath_sizes, area) then local command = "gm convert " .. ngx.var.p_w_picpath_root .. originalUri .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.file; os.execute(command); else ngx.exit(404); end; ';}alias/home/wwwroot/st.xxx/p_w_picpaths/; expires 7d;}
後端獲取文件切換成weed-fs的反向代理,本地文件存儲路徑再規劃一下,或者本地不存,前端加一層varnish,自動處理過時靜態緩存,這樣整個架構基本完成了。shell
http://wiki.nginx.org/HttpLuaModuleZhwindows
http://www.lua.org/後端
http://luajit.org/install.html
https://github.com/chaoslawful/lua-nginx-module/
http://www.iteye.com/topic/1125126?page=2
http://www.graphicsmagick.org/GraphicsMagick.html#details-thumbnail