How to reject or allow specified IP in the Nginx

Nginx denied or allowed to specify the IP, and HTTP access module using the control module (HTTP Access). Checking according to a predetermined sequence control rules, and enable the first access rule that matches the IP.

Examples


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 allowing access to this network 192.168.1.0/24 10.1.1.0/16 and a location field, but is an exception 192.168.1.1.

Match the order of the rules. If you've used Apache, you might think that you are free to control the order of the rules, and they can work, 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
}

 

Guess you like

Origin www.linuxidc.com/Linux/2020-03/162475.htm