Nginx prohibits an IP or an IP segment from accessing the website.

  

We often need to block an IP from accessing our website. Let me introduce how to disable an IP or a certain in nginx. IP section to visit the website, friends who need to know can refer to

Prohibit the writing of a single IP:

Code is as follows deny xxxx;

Prohibition of IP segment writing:

The code is as follows deny 10.0.0.0/24;

It can also be implemented to allow only one IP or some IP segment users to access, all other users are forbidden:

Code is as follows allow Xxxx; allow 10.0.0.0/24; deny all;

Restart nginx to take effect, let's take a look at the example

First set up the following configuration file in the conf directory of nginx, Named blocksip.conf: deny 95.105.25.181; //This is the IP that nginx wants to disable. In the nginx configuration file nginx.conf add: include blocksip.conf;

Restart the nginx service: /usr/local/nginx/sbin/nginx -s reload can take effect. This achieves the effect of nginx banned IP. There are many other formats of blocksip.conf:, you can configure only allowed IP access or IP segment access:

The code is as follows 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.

Copyright © Windows knowledge All Rights Reserved