nginx-ultimate-bad-bot-blocker icon indicating copy to clipboard operation
nginx-ultimate-bad-bot-blocker copied to clipboard

[INSTALLATION] Blocking IP doesn't work

Open krysczajkowski opened this issue 3 years ago • 3 comments
trafficstars

Blocking IP doesn't work. When I put my own IP in blacklist-ips.conf file I still can reach my website.

Copy of nginx.conf


user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}

http {

    server {
      # Bad Bot Blocker
      include /etc/nginx/bots.d/ddos.conf;
      include /etc/nginx/bots.d/blockbots.conf;
    }

	##
	# Basic Settings
	##
	client_max_body_size 10M;
	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
            
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
}



Copy of vhost

server {

    server_name www.mydomain.com mydomain.com;
    
    ##
    # 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;
    
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/krystian/djangoprojectdir;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name www.mydomain.com mydomain.com;
    return 404; # managed by Certbot
 	
}

Blacklist-ips.conf file:


# ------------
# MY BLACKLIST
# ------------

# 111.111.111.111	1;
[My IPv4 here] 1;


krysczajkowski avatar Jul 08 '22 11:07 krysczajkowski

Yes it does work 100% are you trying to blacklist your own server IP?

mitchellkrogza avatar Jul 08 '22 13:07 mitchellkrogza

I try to block my phone's IP just for a test. Maybe it is something wrong with my nginx.conf file, is the server block in the right place?

krysczajkowski avatar Jul 09 '22 09:07 krysczajkowski

I try to block my phone's IP just for a test. Maybe it is something wrong with my nginx.conf file, is the server block in the right place?

Put the two includes at the VERY top of your server{} block before any location{} blocks

mitchellkrogza avatar Jul 09 '22 11:07 mitchellkrogza