Score:-1

How to block IP range with nginx

ru flag

In my server, I use nginx as web server. This server receives many visits from bad bots.

I know how to block specific ip, editing /etc/nginx/nginx.conf file and within the server block, add this line (example): deny 74.208.136.135;

But I want to block all access from 74.208.***.***

Is this possible with nginx?

anx avatar
fr flag
anx
Check the example which is the first thing [in the documentation for `deny`](https://nginx.org/en/docs/http/ngx_http_access_module.html#example)
Ivan Shatsky avatar
gr flag
Use CIDR network address: `deny 75.208.0.0/16;`
Score:2
za flag

The Answer as already been told in the comments

deny accepts as stated in NGINX Manual:

  • hostname
  • IP
  • CIDR
  • Unix-Socket
  • All

Meaning:

deny my.blocked.host
deny 127.0.0.1
deny 127.0.0.1/8
deny unix:/path/to/socket
deny all

The answer to your Request, which is used to Block a Class A Network which is the same as Netmask 255.255.0.0 or in CIDR /16

the Answer to your Question

deny 75.208.0.0/16;
djdomi avatar
za flag
@Diego-Somar i hope i could help you with your Question and would be really glad if you accept it as answer
Diego Somar avatar
ru flag
Hello @djdomi tks your answer. I applied the change on the server, thanks :)
djdomi avatar
za flag
it's Class B not A, damn auto correction ;-) Class A would be 255.0.0.0 or /8 to be fully correct
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.