成功安裝這個組件的前提:必須安裝了zlib-devel ,zlib , libpng ,libpng-devel 這四個組件php
qrencode下載地址<A title=http://fukuchi.org/works/qrencode/qrencode-3.4.4.tar.gz href="http://fukuchi.org/works/qrencode/qrencode-3.4.4.tar.gz" target=_self _href="http://fukuchi.org/works/qrencode/qrencode-3.4.4.tar.gz">http://fukuchi.org/works/qrencode/qrencode-3.4.4.tar.gzhtml
個人下載與解壓路徑 :/usr/local/src/qrencode-3.4.4nginx
執行編譯:shell
./configure --enable-shared --enable-static
若是提示異常,可能會有 找不到 libpng 、zlib,這兩種狀況 ,這說明是沒有安裝相應的devel包,安裝一次就好了。編碼
下面是在nginx上生成二維編碼的一段lua代碼,它是經過nginx的代理來處理後調用的(有傳參)。lua
local function writefile(filename, info) local wfile=io.open(filename, "w") mage.luaassert(wfile) afile:write(info) wfile:close() end local function is_dir(sPath) if type(sPath) ~= "string" then return false end local response = os.execute( "cd " .. sPath ) if response == 0 then return true end return false end local file_exists = function(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false end end local area = nil local originalUri = ngx.var.uri; local originalFile = ngx.var.file; local index = string.find(ngx.var.uri, "png"); if index then originalUri = string.sub(ngx.var.uri, 0, index-2); local index = string.find(originalFile, "png"); originalFile = string.sub(originalFile, 0, index-2) end -- if not file_exists(originalFile) then -- ngx.exit(404) --end local skuIdIndex =string.find(originalFile,'qrencode') skuId=string.sub(originalFile,skuIdIndex+string.len('qrencode')+1,string.len(originalFile)) local command = " qrencode -o "..originalFile..".png 'http://www.hdxw.com/goods/detail?goods_id="..skuId.."'"; os.execute(command); if file_exists(ngx.var.file) then ngx.exec(ngx.var.uri) else ngx.exit(404) end
下面是nginx的配置文件,固然我是作了一個子文件spa
server { listen 80; server_name img.hdxw.com; root /data/htdocs/source; location / { # 這裏是把全部不存在的文件和目錄,全都轉到 index.php 處理 try_files $uri $uri/ /index.php?__q=$uri&$args; } index index.html index.htm index.php; location ^~ /image/qrencode/ { root /data/htdocs/source; set $image_root /data/htdocs/source; set $file "$image_root$uri"; if (!-f $file) { content_by_lua_file lua/qrcode.lua; } proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; index index.html index.htm; expires 7d; } location ~ .*\.(mp4.jpg)$ { root /data/htdocs/source; set $image_root /data/htdocs/source; set $file "$image_root$uri"; if (!-f $file) { content_by_lua_file lua/mp4GrabImage.lua; } proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; index index.html index.htm; expires 7d; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { root /data/htdocs/source; set $image_root /data/htdocs/source; set $file "$image_root$uri"; if (!-f $file) { content_by_lua_file lua/image.lua; } proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache_valid 200 304 12h; proxy_cache_key $uri$is_args$args; index index.html index.htm; expires 7d; } } log_format access.img '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /data/management/logs/img.access.log access.img;