To block and deny access to specific IP addresses or network subnets in Nginx, you can use the deny
and allow
directives in the location
block of your Nginx configuration file.
For example, to deny access to a specific IP address, you can use the following configuration:
rt refeo:lautturi.comlocation / { deny 192.168.1.100; allow all; }
This will deny access to the IP address 192.168.1.100
, while allowing access to all other IP addresses.
To deny access to a range of IP addresses or a network subnet, you can use a wildcard mask with the deny
directive. For example, to deny access to the entire 192.168.1.0/24
network subnet, you can use the following configuration:
location / { deny 192.168.1.0/24; allow all; }
This will deny access to all IP addresses in the 192.168.1.0/24
subnet, while allowing access to all other IP addresses.
Keep in mind that the deny
and allow
directives are processed in the order they appear in the configuration file. It is important to place the deny
directives before the allow
directives, as Nginx will stop processing the allow
and deny
directives as soon as it encounters a match.
It is also important to note that the allow
and deny
directives only work in the http
context of the Nginx configuration file. They will not work in the server
or location
blocks of the stream
context.