Open imunisasi opened 4 years ago
Your includes are in the wrong place. Please post your config.
I also have this issue:
sudo nginx -t nginx: [emerg] "if" directive is not allowed here in /etc/nginx/bots.d/blockbots .conf:58 nginx: configuration file /etc/nginx/nginx.conf test failed
my vhost config is a default one so far and not configured for my site, yet...
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html/;
##
# Nginx Bad Bot Blocker Includes
# REPO: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
##
include /etc/nginx/bots.d/ddos.conf;
include /etc/nginx/bots.d/blockbots.conf;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
# disable access to hidden files
location ~ /\.ht {
access_log off;
log_not_found off;
deny all;
}
}
also to add, I'm running the following ubuntu & nginx versions:
ubuntu 20.04 nginx version: nginx/1.17.10
I had this issue as well, and found at least a partial cause: You're inserting content into the wrong place in the config file. You need to not only ignore commented-out lines, you also need to check for multiple server definitions in a single file.
In the first case, simply ignoring the commented lines would be good enough.
In this second case, there's a second server definition with a redirect to change a subdomain. In this case you need to also check each file for multiple server definitions.
the code that controls where the includes are inserted is around line 460
of setup-ngxblocker
:
line=$(find_includes $MAIN_CONF sendfile last http first '\}' last )
different distributions use different style nginx.conf
so it is difficult to cover every use case
Bump @mitchellkrogza
This is still broken. Issue occurs on a standard Nginx vhost managed by Let’s Encrypt Certbot (which creates 2 server blocks in each vhost file).
nginx: [emerg] "if" directive is not allowed here in /etc/nginx/bots.d/blockbots.conf:58 nginx: configuration file /etc/nginx/nginx.conf test failed
Ubuntu 19,04 minimal Nginx 1.16.1