User Tools

Site Tools


linux:nginx

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/;
}

linux/nginx.txt · Last modified: 2025/08/11 08:52 by srohr_admin

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki