Top

Nginx whitelist specific IP

Oct 07, 2021 | 4354 views

#Web-frontend


Code example, whitelist keywords in URI for specific IP


server {
#...
    
    location / { 
        set $deny_access off;
        if ($remote_addr != "specific-ip-here") {
            set $deny_access on;
        }
        if ($uri ~ "^/(keyword1|keyword2)/" ) {
            set $deny_access on$deny_access;
        }
        # add_header X-debug-message "deny_access: $deny_access" always; # debug
        if ($deny_access = onon) { return 404; }
        # ...
    }
#...
}



Reference:


Leave a comment

0 comments