diff --git a/install/nginx-cloudflare-fail2ban.sh b/install/nginx-cloudflare-fail2ban.sh index e1bef05..9f65ba3 100644 --- a/install/nginx-cloudflare-fail2ban.sh +++ b/install/nginx-cloudflare-fail2ban.sh @@ -10,6 +10,21 @@ fi echo "Installing required packages..." apt-get install -y nginx-extras +# Add load_module directive to nginx.conf if not present +echo "Adding load_module directive to nginx.conf if needed..." +if ! grep -q "^load_module.*ngx_http_js_module.so" /etc/nginx/nginx.conf; then + # Create temporary file + sed '/^events {/i load_module modules/ngx_http_js_module.so;' /etc/nginx/nginx.conf > /tmp/nginx.conf.tmp + # Check if the modification was successful + if nginx -t -c /tmp/nginx.conf.tmp; then + mv /tmp/nginx.conf.tmp /etc/nginx/nginx.conf + else + rm /tmp/nginx.conf.tmp + echo "Failed to modify nginx.conf safely. Please add 'load_module modules/ngx_http_js_module.so;' manually." + exit 1 + fi +fi + # Create the fail2ban check script echo "Creating fail2ban check script..." tee /usr/local/bin/check_fail2ban.sh << 'SCRIPT' diff --git a/install/nginx-conf/10-fail2ban-check.conf b/install/nginx-conf/10-fail2ban-check.conf index f8ad430..e2b5e12 100644 --- a/install/nginx-conf/10-fail2ban-check.conf +++ b/install/nginx-conf/10-fail2ban-check.conf @@ -1,5 +1,3 @@ -load_module modules/ngx_http_js_module.so; - js_import /etc/nginx/modules-available/check_ban.js; js_set $exec_check_ban check_ban.checkBan;