Table of Contents

Nginx


Whitelist certain IP's

Add the following directives with your desire IP inside the server section of /etc/nginx/sites-available

server {
    allow 192.168.0.0; # here goes the IP you want to allow
    deny all;
    # ...
}

You can also write the directives inside the http section to apply it to multiple virtual hosts.

http {
    allow 192.168.0.0; # here goes the IP you want to allow
    deny all;
    
    server {
        server_name page1.rackspace.com;
        # ...
    }
    
    server {
        server_name page2.rackspace.com;
        # ...
    }
}

Redirect blocked IP's to different URL

Use the error_page directive for this.

location / {
    allow 198.168.0.1;
    deny all;
    error_page 403 http://www.google.com/;
}