crowdsecurity / cs-nginx-bouncer

CrowdSec bouncer for Nginx
MIT License
49 stars 9 forks source link

cant not run nginx with lua #5

Closed zhixiangjoy closed 3 years ago

zhixiangjoy commented 3 years ago

when I follow the step , I can't restart nginx :

# nginx -t
nginx: [emerg] unknown directive "lua_package_path" in /etc/nginx/conf.d/crowdsec_nginx.conf:1

There is some messages:

apt-get install lua5.3 libnginx-mod-http-lua lua-sec
Reading package lists... Done
Building dependency tree
Reading state information... Done
lua-sec is already the newest version (0.9-3).
lua5.3 is already the newest version (5.3.3-1.1ubuntu2).
libnginx-mod-http-lua is already the newest version (1.18.0-0ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
---
# cat /etc/issue
Ubuntu 20.04.1 LTS \n \l
----
# nginx -V
nginx version: nginx/1.18.0 (Ubuntu)
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module--add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-auth-pam --add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-dav-ext --add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-echo --add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-upstream-fair --add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-subs-filter --add-dynamic-module=/build/nginx-5J5hor/nginx-1.18.0/debian/modules/http-geoip2

Should I need install nginx-lua-module by mannul or install openresty? Thanks !

zhixiangjoy commented 3 years ago

Final I try to install openresty ,but still get errors:

Dec 11 11:21:49 nginx-proxy03 systemd[1]: Starting The OpenResty Application Platform...
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:  nginx: [error] init_by_lua error: /usr/local/lua/crowdsec/lrucache.lua:49: attempt to redefine 'lrucache_queue_s' at line 2
Dec 11 11:21:49 nginx-proxy03 nginx[4326]: stack traceback:
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         [C]: in function 'cdef'
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         /usr/local/lua/crowdsec/lrucache.lua:49: in main chunk
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         [C]: in function 'require'
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         /usr/local/lua/crowdsec/CrowdSec.lua:4: in main chunk
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         [C]: in function 'require'
Dec 11 11:21:49 nginx-proxy03 nginx[4326]:         init_by_lua:2: in main chunk
Dec 11 11:21:49 nginx-proxy03 systemd[1]: openresty.service: Control process exited, code=exited, status=1/FAILURE
Dec 11 11:21:49 nginx-proxy03 systemd[1]: openresty.service: Failed with result 'exit-code'.
Dec 11 11:21:49 nginx-proxy03 systemd[1]: Failed to start The OpenResty Application Platform.
buixor commented 3 years ago

Hello,

Thanks for the report ! You shouldn't have to use openresty, nginx mod lua should do the trick.

The error nginx: [emerg] unknown directive "lua_package_path" in /etc/nginx/conf.d/crowdsec_nginx.conf:1 looks like lua was actually not installed as a nginx module (this directive is one of nginx).

Can you check if lua is correctly enabled at nginx level ?

Thanks,

buixor commented 3 years ago

@zhixiangjoy any update on this ?

zhixiangjoy commented 3 years ago

Thanks for your reply, It's my fault。I had modify the nginx.conf which had delete the line : include /etc/nginx/modules-enabled/*.conf; In that situation, nginx can't loading the lua lib.