crowdsecurity / cs-nginx-bouncer

CrowdSec bouncer for Nginx
MIT License
48 stars 8 forks source link

Installing crowdsec-nginx-bouncer failed with lua.h issue #42

Closed houdini69 closed 1 year ago

houdini69 commented 1 year ago

I've tried to install crowdsec-nginx-bouncer with apt on Debian Bullseye but get this error,

sudo apt install nginx lua5.1 libnginx-mod-http-lua luarocks gettext-base lua-cjson .. Installing https://luarocks.org/lua-cjson-2.1.0.10-1.src.rock gcc -O2 -fPIC -I/usr/include/lua5.1 -c lua_cjson.c -o lua_cjson.o lua_cjson.c:44:10: fatal error: lua.h: Aucun fichier ou dossier de ce type 44 | #include | ^~~ compilation terminated.

Error: Build error: Failed compiling object lua_cjson.o cscli/crowdsec is present, generating API key API Key : 85756596ce00a639f705c9c2edbf3a25 Restart nginx to enable the crowdsec bouncer : sudo systemctl restart nginx ....

uname -a Linux monplaisir.ddns.net 5.19.17-meson64 #22.11.1 SMP PREEMPT Wed Nov 30 11:05:42 UTC 2022 aarch64 GNU/Linux

Installation of crowdsec was successful following official installation instruction.

LaurenceJJones commented 1 year ago

Hey it is not directly the bouncer, some reason the dependency lua_cjson is failing to compile cause it cant find the file

Could you run sudo find / -name "lua.h"

houdini69 commented 1 year ago

sudo find / -name "lua.h" /usr/include/lua5.2/lua.h

So install script is looking for lua.h in /usr/include/lua5.1!

houdini69 commented 1 year ago

sudo apt install lua5.2 seems to solve this issue. However sudo nginx -t gives sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: [error] init_by_lua error: /usr/lib/crowdsec/lua/plugins/crowdsec/iputils.lua:22: module 'ffi' not found: no field package.preload['ffi'] no file '/usr/lib/crowdsec/lua/ffi.lua' no file './ffi.lua' no file '/usr/local/share/lua/5.1/ffi.lua' no file '/usr/local/share/lua/5.1/ffi/init.lua' no file '/usr/local/lib/lua/5.1/ffi.lua' no file '/usr/local/lib/lua/5.1/ffi/init.lua' no file '/usr/share/lua/5.1/ffi.lua' no file '/usr/share/lua/5.1/ffi/init.lua' no file './ffi.lua' no file './ffi.so' no file '/usr/local/lib/lua/5.1/ffi.so' no file '/usr/lib/aarch64-linux-gnu/lua/5.1/ffi.so' no file '/usr/lib/lua/5.1/ffi.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'require' /usr/lib/crowdsec/lua/plugins/crowdsec/iputils.lua:22: in main chunk [C]: in function 'require' /usr/lib/crowdsec/lua/crowdsec.lua:4: in main chunk [C]: in function 'require' init_by_lua:2: in main chunk nginx: configuration file /etc/nginx/nginx.conf test failed

SirJohn2024 commented 1 year ago

Starting from here: https://stackoverflow.com/questions/74914141/cannot-install-ffi-library-for-lua-luajit I bypass the problen this way:

git clone https://github.com/facebookarchive/luaffifb cd luaffifb luarocks make chmod '0755' '/usr/local/lib/lua/5.1/ffi.so'

after that nginx stop complaining... Hope this helps...

houdini69 commented 1 year ago

sudo luarocks make gcc -O2 -fPIC -I/usr/include/lua5.1 -c call.c -o call.o -Idynasm In file included from call.c:9: ffi.h:30:11: fatal error: lua.h: Aucun fichier ou dossier de ce type 30 | # include | ^~~ compilation terminated.

Error: Build error: Failed compiling object call.o

SirJohn2024 commented 1 year ago

Have you tried sudo apt install libffi-dev?

Maybe you're missing /usr/include/lua5.x/lua.h...

SirJohn2024 commented 1 year ago

Sorry, the correct package is liblua5.x-dev not libffi-dev.. My bad...😏

houdini69 commented 1 year ago

Thanks for you help! I have to install first liblua5.1-0.dev and then install luaffifb as suggested

But nginx -t throws

nginx: [error] [lua] crowdsec.lua:46: init(): error loading recaptcha plugin: no recaptcha site key provided, can't use recaptcha

houdini69 commented 1 year ago

Ok. I can disable recaptcha temporaly and look at its configuration...

SirJohn2024 commented 1 year ago

Check this https://github.com/crowdsecurity/lua-cs-bouncer

git clone https://github.com/crowdsecurity/lua-cs-bouncer.git Read the README.md, I had to install manually, but seems to do the trick...

houdini69 commented 1 year ago

Check this https://github.com/crowdsecurity/lua-cs-bouncer

git clone https://github.com/crowdsecurity/lua-cs-bouncer.git Read the README.md, I had to install manually, but seems to do the trick...

You mean installing lua-cs-bouncer will fix nginx error? I can't disable recapcha plugin.