添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
专栏
天翼云开发者社区

lua-zlib模块安装与使用

CDN

网络

2023-06-29 16:08:49

lua-zlib包用于nginx上对gzip数据进行解压缩,可将lua-zlib编译成一个动态链接库zlib.so,便于lua引用。

github: https://github.com/brimworks/lua-zlib

1. 安装

1.1 检查是否安装zlib

$ rpm -qa zlib
zlib-1.2.3-29.el6.x86_64

1.2 安装cmake

检查gcc, g++, make是否安装

gcc -v
g++ -v
make -v

若未安装,则:yum install -y gcc gcc-c++ make automake

安装cmake

cd /usr/local
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
tar -xvzf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap
gmake
gmake install
检查cmake是否安装成功:
$ cmake --version
cmake version 2.8.10.2

1.3 安装lua-zlib

(1)download
cd /usr/local
wget https://github.com/brimworks/lua-zlib/archive/master.zip
unzip lua-zlib-master.zip
(2)cmake
cd /usr/local/lua-zlib-master
cmake -DLUA_INCLUDE_DIR=/usr/local/openresty/luajit/include/luajit-2.1 -DLUA_LIBRARIES=/usr/local/openresty/luajit/lib -DUSE_LUAJIT=ON -DUSE_LUA=OFF
cp zlib.so /usr/local/openresty/lualib/zlib.so

2. zlib包使用

local zip = require(zlib) 
    local v,mv,pv=zip.version()
    local str_data
    -- ngx.log(ngx.INFO, "zip.version(): ", v, ", ", mv, ", ", pv)
    local req_cotent_encoding = ngx.req.get_headers()["Content-Encoding"]
    if req_cotent_encoding == "gzip" then
        ngx.log(ngx.INFO, "req_cotent_encoding = gzip")
        -- 解压缩
        local inflate = zip.inflate()
        str_data = inflate(data)
        ngx.log(ngx.INFO, "raw data: ", data, ", after inflate str_data: ", str_data)
        -- 压缩验证
        --[[local deflate = zip.deflate()
        str_data = deflate(data)
        ngx.log(ngx.INFO, "raw data: ", data, ", after deflate str_data: ", str_data)]]--
        ngx.log(ngx.INFO, "req_cotent_encoding ~= gzip")
        str_data = data

 

  • 0
  • 0
  • 0
0 评论