Home >Backend Development >PHP Tutorial >nginx prohibits access to an IP

nginx prohibits access to an IP

WBOY
WBOYOriginal
2016-08-08 09:27:261230browse
First create the following configuration file and place it under the conf directory of nginx, named blocksip.conf:
deny 95.105.25.181;
Save it.
Add in the nginx configuration file nginx.conf: include blocksip.conf;
Restart the nginx service: /usr/local/nginx/sbin/nginx -s reload and it will take effect.
blocksip.conf: There are many formats, you can configure only allowed IP access or IP segment access:
deny IP;
allow IP;
# block all ips
deny all ;
# allow all ips
allow all;

The network segment is written like this: 192.168.1.0/24.

deny 192.168.1.11;
deny 192.168.1.123;
deny 10.0.1.0/24;

If you want to implement such an application, besides a few Except for IP, all others are rejected.

Then you need to write like this in ip.balcklist


allow 1.1.1.1; In server "{}", adding deny IP address within the braces restricts access to a certain IP address; allow IP address only allows access to a certain IP address;

#The command to block a single IP is

deny

123.45.6.7#The command to block the entire segment from 123.0.0.1 to 123.255.255.254deny 123.0.0.0/8#Block the IP segment from 123 .45.0.1 to 123.45. The command for 255.254deny 124.45.0.0/16#The command to block the IP segment from 123.45.6.1 to 123.45.6.254 is deny 123.45.6. 0/24
The above introduces nginx to ban access to a certain IP, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn