How to deny or allow specified IP in Nginx
Nginx denies or allows the specified IP and uses the module HTTP Access Control Module (HTTP Access). The control rules are checked in the stated order, and the first access rule that matches the IP will be enabled.
Example
location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
deny all;
}
In the above example, only the 192.168.1.0/24 and 10.1.1.0/16 network segments are allowed to access this location field, but 192.168.1.1 is an exception.
Pay attention to the matching order of the rules. If you have used apache, you may think that you can control the order of the rules at will and they can work normally, but in fact, they do not work. The following example will reject all connections:
location / {
deny all;
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/1
}