Nginx return `444` on deny
I have an Nginx
instance where I only want to allow certain IP ranges:
allow 192.168.0.0/16;
deny all;
This works fine, however when denied, a 403
is returned.
I don't denied IPs to know I have a web server at all. However can I return 444
instead, aka drop the packet?
Solution 1:
actually you can use geo directive, also if and return directive to achieve what you mean. Here is configuration you need to use:
http{
...
geo $remote_addr $allowed_trafic {
default false;
192.168.0.0/16 true;
}
}
server {
...
if ( $allowed_trafic = 'false'){
return 444;
}
...
}
Hope this help you. Thanks.
Solution 2:
You could try this one:
- create file "ip.conf", then include to "nginx.conf"
- The "ip.conf" should look like:
geo $bad_ip {
192.168.0.0/16;
10.0.0.0/16;
default 1;
}
- The "app.conf" file should look like:
location / {
if ($bad_ip) {
return 444;
}
proxy_pass http://app/;
}