成功安装这个组件的前提:必须安装了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;