p0pr0ck5 / lua-resty-waf

High-performance WAF built on the OpenResty stack
GNU General Public License v3.0
1.28k stars 305 forks source link

Init failing due to missing rex_pcre #284

Closed kwaping closed 7 years ago

kwaping commented 7 years ago

Hi Robert,

I believe I've followed all your instructions, and I'm using a current OpenResty with pcre compiled in, but the initialization of lua-resty-waf is failing due to a missing rex_pcre.

nginx -t nginx: [error] init_by_lua error: /usr/local/openresty/site/lualib/resty/waf/translate.lua:5: module 'rex_pcre' not found: no field package.preload['rex_pcre'] no file '/usr/local/openresty/site/lualib/rex_pcre.lua' no file '/usr/local/openresty/site/lualib/rex_pcre/init.lua' no file '/usr/local/openresty/lualib/rex_pcre.lua' no file '/usr/local/openresty/lualib/rex_pcre/init.lua' no file './rex_pcre.lua' no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/rex_pcre.lua' no file '/usr/local/share/lua/5.1/rex_pcre.lua' no file '/usr/local/share/lua/5.1/rex_pcre/init.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/rex_pcre.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/rex_pcre/init.lua' no file '/usr/local/openresty/site/lualib/rex_pcre.so' no file '/usr/local/openresty/lualib/rex_pcre.so' no file './rex_pcre.so' no file '/usr/local/lib/lua/5.1/rex_pcre.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/rex_pcre.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' /usr/local/openresty/site/lualib/resty/waf/translate.lua:5: in main chunk [C]: in function 'require' /usr/local/openresty/site/lualib/resty/waf.lua:14: in main chunk [C]: in function 'require' init_by_lua:3: in main chunk nginx: configuration file /etc/nginx/nginx.conf test failed

Can you please help me figure out what I've missed in my setup?

kwaping commented 7 years ago

Update: I tried installing lrexlib-pcre via luarocks, which complained about headers not found, so I installed pcre-devel and tried again. Got lrexlib installed but still no change in the Nginx error output.

kwaping commented 7 years ago

I should also point out that I originally installed lua-resty-waf via luarocks, in case that makes a difference.

kwaping commented 7 years ago

Fixed! For some reason, openresty wasn't looking for the library where it was installed. A symlink took care of it.

[root ~]# nginx -t nginx: [error] init_by_lua error: /usr/local/openresty/site/lualib/resty/waf/translate.lua:5: module 'rex_pcre' not found: no field package.preload['rex_pcre'] no file '/usr/local/openresty/site/lualib/rex_pcre.lua' no file '/usr/local/openresty/site/lualib/rex_pcre/init.lua' no file '/usr/local/openresty/lualib/rex_pcre.lua' no file '/usr/local/openresty/lualib/rex_pcre/init.lua' no file './rex_pcre.lua' no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta2/rex_pcre.lua' no file '/usr/local/share/lua/5.1/rex_pcre.lua' no file '/usr/local/share/lua/5.1/rex_pcre/init.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/rex_pcre.lua' no file '/usr/local/openresty/luajit/share/lua/5.1/rex_pcre/init.lua' no file '/usr/local/openresty/site/lualib/rex_pcre.so' no file '/usr/local/openresty/lualib/rex_pcre.so' no file './rex_pcre.so' no file '/usr/local/lib/lua/5.1/rex_pcre.so' no file '/usr/local/openresty/luajit/lib/lua/5.1/rex_pcre.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' /usr/local/openresty/site/lualib/resty/waf/translate.lua:5: in main chunk [C]: in function 'require' /usr/local/openresty/site/lualib/resty/waf.lua:14: in main chunk [C]: in function 'require' init_by_lua:3: in main chunk nginx: configuration file /etc/nginx/nginx.conf test failed

########### the fix vvv ############# [root ~]# ln -s /usr/lib64/lua/5.1/rex_pcre.so /usr/local/openresty/lualib/rex_pcre.so #####################################

[root ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root ~]#

p0pr0ck5 commented 7 years ago

Hey @kwaping,

Apologies for the delayed response. Yep, your analysis is correct. BTW we end up doing the same thing for Travis: https://github.com/p0pr0ck5/lua-resty-waf/blob/master/.travis.yml#L33

This is probably something we can handle in the Makefile. Patches welcome :)

kwaping commented 7 years ago

Thank you! I'll see what I can wrangle up - I'd rather figure out the root cause than patch it with a band-aid like that symlink.