Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to deny range of IPs on Nginx

Is it possible to deny range like 43.249.64.0-43.249.85.255? Or only by mask like 43.249.64.0/19 which includes up to 43.249.95.255 which makes it not good decision.

like image 916
Igor Yavych Avatar asked Jun 23 '13 20:06

Igor Yavych


People also ask

How do I restrict access to nginx?

Restricting Directory AccessLog in to the web server. Locate the Nginx configuration template (see "Locating the Nginx configuration file"). Add the deny directive (see "The Deny Directive") to the server block of your site's configuration. Save your changes and restart Nginx.


1 Answers

You can block IP ranges using the CIDR notation. Have a look at the article 'Nginx Block And Deny IP Address OR Network Subnets'

You can use IP range calculators like this one that do the math for you. For example your range '43.249.64.0-43.249.85.255' can be expressed as:

43.249.64.0/20
43.249.80.0/22
43.249.84.0/23

like image 161
djf Avatar answered Sep 16 '22 16:09

djf