I have this server block:
server {
server_name doamin.tld;
set $maintenance on;
if ($remote_addr ~ (127.0.0.1|10.1.1.10)) {
set $maintenance off;
}
if ($maintenance = on) {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
root /var/www/html/global;
rewrite ^(.*)$ /holding-page.html break;
}
root html;
access_log logs/doamin.tld.access.log;
error_log logs/doamin.tld.error.log;
include ../conf/default.d/location.conf;
}
What is the correct way to pass a list to the $remote_addr
instead of coding it like (127.0.0.1| etc...)?
Click IP Address Manager > IP Addresses > Manage Subnets & IP Addresses. In the network tree pane on the left, click the subnet to which you want to add your new IP address range. Click Add IP Range. Enter the starting IP address and the ending IP address of your IP address range.
The most common subnet you will see is 255.255. 255.0. So if two addresses match in the first three sections (reading left to right), and the subnet is 255.255. 255.0 for both addresses, they are in the same subnet.
The formula to calculate the number of assignable IP address to CIDR networks is similar to classful networking. Subtract the number of network bits from 32. Raise 2 to that power and subtract 2 for the network and broadcast addresses. For example, a /24 network has 232-24 - 2 addresses available for host assignment.
Use the nginx map directive to set the $maintenance
value according to the $remote_addr
:
map $remote_addr $maintenance {
default on;
127.0.0.1 off;
10.1.1.10 off;
10.*.1.* off;
}
server {
server_name doamin.tld;
if ($maintenance = on) {
return 503;
}
# ... your code ...
}
Take a look at the include directive if you want to take the IPs list in a separate file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With