searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

lua-zlib模块安装与使用

2023-06-29 08:08:49
178
0

 

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
make
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)]]--
    else
        ngx.log(ngx.INFO, "req_cotent_encoding ~= gzip")
        str_data = data
    end

 

0条评论
0 / 1000
lucky_lyw
4文章数
0粉丝数
lucky_lyw
4 文章 | 0 粉丝
lucky_lyw
4文章数
0粉丝数
lucky_lyw
4 文章 | 0 粉丝
原创

lua-zlib模块安装与使用

2023-06-29 08:08:49
178
0

 

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
make
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)]]--
    else
        ngx.log(ngx.INFO, "req_cotent_encoding ~= gzip")
        str_data = data
    end

 

文章来自个人专栏
ccslyw
4 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
0
0