: This article describes how to disable an IP address from accessing the site through nginx. For more information about PHP tutorials, see. If you want to block an IP address from your website, you cannot open the website. For more information, see/etc/hosts. deny. Actually, it is not feasible. I don't want to use iptable. it's too troublesome. Check nginx to prevent ip access.
First, create the following configuration file and place it under the nginx conf directory, and name it blocksip. conf:
Deny 4.4.4.4 // This is the IP address to be disabled by nginx
Save it.
Add: include blocksip. conf to the nginx configuration file nginx. conf, and restart nginx to take effect. When the blocked ip address opens the site, the following message is displayed:
403 Forbidden
Blocksip. conf: There are many other 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 CIDR block format is as follows: 192.168.1.0/24.
The above section describes how to disable an IP address from accessing the site in nginx, including some content. if you are interested in the PHP Tutorial.