How to add zlib lua support to OpenResty

1,230 views
Skip to first unread message

David Jiménez

unread,
Nov 21, 2016, 11:54:43 AM11/21/16
to openresty-en
Hello,

I'm trying to use zlib to decompress with a lua script the responses of a server I'm proxying: Here is the part of the code where I'm doing the "required":

            header_filter_by_lua '
                if ngx.header.content_encoding == "gzip" then
                    local zlib = require "zlib"
                    ngx.ctx.inflate = zlib.inflate()
                    ngx.header.content_length = nil
                    ngx.header.content_encoding = nil
                end
            '
;


I have zlib-lua (https://github.com/brimworks/lua-zlib) installed on my machine and working (I can tell that because I can open on a CMD the lua interpreter and execute require 'zlib' without problems. However it doesn't seem to be working on OpenResty and have no idea on how to properly install it. Here's the log of the error:


 
2016/11/21 17:28:26 [error] 14820#14264: *23 failed to run header_filter_by_lua*: header_filter_by_lua:3: module 'zlib' not found:
 
no field package.preload['zlib']
 
no file './site/lualib/zlib.lua'
 
no file './site/lualib/zlib/init.lua'
 
no file './lualib/zlib.lua'
 
no file './lualib/zlib/init.lua'
 
no file '.\zlib.lua'
 
no file 'C:\OpenResty\lualib\zlib.lua'
 
no file 'C:\OpenResty\lua\zlib.lua'
 
no file 'C:\OpenResty\lua\zlib\init.lua'
 
no file './site/lualib/zlib.so'
 
no file './lualib/zlib.so'
 
no file '.\zlib.dll'
 
no file 'C:\OpenResty\lualib\zlib.so'
 
no file 'C:\OpenResty\zlib.dll'
 
no file 'C:\OpenResty\loadall.dll'
stack traceback
:
 
[C]: in function 'require'
 header_filter_by_lua
:3: in function <header_filter_by_lua:1> while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://92.123.73.10:80/", host: "localhost:8080"
2016/11/21 17:30:02 [error] 14956#13520: *1 failed to run header_filter_by_lua*: error loading module 'zlib' from file '.\zlib.dll':
 
The specified procedure could not be found.


How can I properly install zlib support for OpenResty?

Thank you,

David

Bingwu Yang

unread,
Nov 21, 2016, 10:01:10 PM11/21/16
to openre...@googlegroups.com
you should have a look at this lua_package_path

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Jiménez

unread,
Nov 22, 2016, 8:39:23 AM11/22/16
to openresty-en
Thanks for the suggestion, I solved my issues by using Linux to execute nginx, obtain the package.path and package.cpath from lua and put them in nginx.conf this way:

    lua_package_path "./?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua";
   
    lua_package_cpath
"./?.so;/usr/local/lib/lua/5.1/?.so;/usr/lib/i386-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so";

And now everything works fine :D
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages