Is it possible to conditionally allow or deny IP in NGINX? This isn't allowed.
if($example){
deny all;
}
if ($example2){
allow all;
}
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityIs it possible to conditionally allow or deny IP in NGINX? This isn't allowed.
if($example){
deny all;
}
if ($example2){
allow all;
}
You can do this by using the geo module. This will only allow ip 1.1.1.1 and 2.2.2.2 to access the endpoint. You could reverse the logic to allow all ips and only deny a specific few.
geo $trusted_user {
default 0;
1.1.1.1 1;
2.2.2.2 1;
}
server
{
if ( $trusted_user ~ 0 ) { return 444; }
}