Restrict subfolder access by ip in NGINX

To restrict subfolder access by IP in NGINX, you can use the allow and deny directives in your server block configuration.

First, create a new location block for the subfolder you want to restrict access to:

location /subfolder {
  # add access control directives here
}

Then, use the allow and deny directives to specify which IP addresses are allowed to access the subfolder:

location /subfolder {
  # allow only specific IP addresses
  allow 192.168.1.1;
  allow 10.0.0.1;
  deny all;
}

In this example, only the IP addresses 192.168.1.1 and 10.0.0.1 are allowed to access the subfolder. All other IP addresses will be denied access.

You can also use CIDR notation to specify ranges of IP addresses:

location /subfolder {
  # allow a range of IP addresses
  allow 192.168.1.0/24;
  deny all;
}

In this example, all IP addresses in the range 192.168.1.0 to 192.168.1.255 will be allowed to access the subfolder.

Remember to reload or restart NGINX after making changes to your configuration file for the changes to take effect.

Read more here: Source link