一、下載和安裝lua_zlibgit
wget https://github.com/brimworks/lua-zlib/archive/master.zip unzip master.zip cd lua-zlib-master cmake -DLUA_INCLUDE_DIR=/usr/local/openresty/luajit/include/luajit-2.1 make cp zlib.so /usr/local/openresty/lualib/zlib.so
注:安裝lua_zlib須要lua或luajit的支持,因此在cmake時須要指定lua的路徑。github
二、使用lua_zlib來接收gzip請求
ui
local zlib = require "zlib" local encoding = ngx.req.get_headers()["Content-Encoding"] ngx.req.read_body(); if encoding == "gzip" then local body = ngx.req.get_body_data() if body then local stream = zlib.inflate() ngx.req.set_body_data(stream(body)) end end