Block by IP

Sometimes, your site may fall victim to an overly aggressive or problematic user. Blocking access to your server for these is very straightforward, with a simple edit to your domain's ___general/example.com.conf file

Eg. To block the IP 192.168.1.1

deny 192.168.1.1;

Eg. To block the IP range 192.168.1.0 - 192.168.1.254

deny 192.168.1.0/24;

Alternatively, if you want to give a discrete message, rather than an outright block (perhaps to allow for humans to contact you if there is an error), then a rewrite would be more suitable. Unfortunately, you cannot use CIDR subnetting for Nginx conditional statements, so you are restricted to using Perl REGEX to achieve the same.

Eg. To redirect all requests to a static HTML page for 192.168.1.1

if ($remote_addr ~* "192\.168\.1\.1") {
  rewrite .* /no-crawl-bots.html last;
}

Eg. To redirect all requests to a static HTML page for the range 192.168.1.0 - 192.168.1.254

if ($remote_addr ~* "^192\.168\.1\.([1-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-4]))$") {
  rewrite .* /no-crawl-bots.html last;
}

Then just make a normal HTML file in /no-crawl-bots.html with whatever message you would like to pass to the user.