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_by_lua error #278

Closed JoyChou93 closed 7 years ago

JoyChou93 commented 7 years ago

When I install openresty, I use --with-pcre=/usr/local/src/pcre-8.39 . But now, the error is rex_pcre' not found:

detail:

$ sudo /usr/local/openresty/nginx/sbin/nginx -s reload
[sudo] password for xxx:
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
yvesb commented 7 years ago

Hi,

First of all, @p0pr0ck5 , thank you for the work providing this lua resty waf. Also, I am by no mean and expert but on a learning curve instead trying to set up this WAF for tests.

Having said that, on Debian Jessie, "apt-get install libpcre3-dev" did solve this problem for me.

Hope this helps.

FWIW, I first tried to make this install on Centos 7 (using openresty Yum Centos repository) and experienced the same issue. Haven't tried yet to test again on Centos.

p0pr0ck5 commented 7 years ago

Hi,

Sorry for the delayed response. @JoyChou93 make you sure install the dependencies needed for lua-resty-waf, which should automatically occur when running make install. What I've found is that older versions of Luarocks are not properly installing lrexlib-pcre, so you may need to install this manually (like we do in the Travis config: https://github.com/p0pr0ck5/lua-resty-waf/blob/master/.travis.yml#L33). Note that the luarocks package is not the same thing and compiling OpenResty with --with-pcre; the former is a Lua binding to the system PCRE lib, the other statically compiles PCRE into the nginx binary.

@yvesb thanks for chiming in :)

talkwithmurtuza commented 6 years ago

Hi,

I am getting this error in Centos 7. I have already installed all necessary packages related to openresty. I have installed pcre, pcre-devel and pcre-static but still I am getting above error. Any idea?

dataviruset commented 6 years ago

I did an strace nginx -t to find out that my default installation of OpenResty using official RPM packages on CentOS 7 couldn't find rex_pcre.so. Solved it by adding a soft link, not sure if it is the best solution, but hopefully this will help someone else out there having the same problem :)

yum install gcc gcc-c++ lua-devel openresty-opm luarocks
luarocks install lrexlib-pcre 2.7.2-1
ln -s /usr/lib64/lua/5.1/rex_pcre.so /usr/local/openresty/luajit/lib/lua/5.1/rex_pcre.so
luarocks install lua-resty-waf