需要安装qrencode和libpng
yum install libpng-devel lua lua-devel -y
wget
tar -zxvf qrencode-4.0.2.tar.gz
cd qrencode-4.0.2
./configure
make
make install
cd ..
git clone
cd qrencode
make #可能会出问题
//mac下面可以用gcc编译
gcc -bundle -undefined dynamic_lookup -lpng -lqrencode -I/usr/local/openresty/luajit/include/luajit-2.1/ qrencode.c -o qrencode.so
cp qrencode.so /usr/local/openresty/lualib/
vi nginx.conf
....
location = /qrcode {
content_by_lua_block {
local qr = require("qrencode")
local args = ngx.req.get_uri_args()
local url = args.url
if url == nil or url== "" then
ngx.print('')
ngx.exit(201)
end
ngx.header.content_type = 'image/png'
ngx.say(qr {
text=url,
level="L",
kanji=false,
ansi=false,
size=4,
margin=2,
symversion=0,
dpi=78,
casesensitive=true,
foreground="000000",
background="FFFFFF"
})
}
add_header Pragma "no-cache";
add_header Cache-Control "no-cache, max-age=0, must-revalidate";
}
....
打开网站
http://localhost:8080/qrcode?url=http://badb0y.blog.chinaunix.net
阅读(1851) | 评论(0) | 转发(0) |