2

Is there something special needed to match subnets in nginx when using map? I have the below configuration in the http {} block. The client IP is 10.0.3.1. If i remove the 10.0.3.1 entry it always returns deny instead of matching the 10.0.3.0/24 subnet. Is there a nginx module required that i'm missing or something ?

I'm basing this config on some blog articles but can't find any official documentation to say this notation is supported.

map $remote_addr $allowed {
     10.0.3.1 allow;
     10.0.2.0/24 allow;
     10.0.3.0/24 allow;
     default deny;
}
2

The map directive maps strings, so it is possible to represent 10.0.3.0/24 as a regular expression and continue to use the map directive. But have you considered the geo directive that does support IP address syntax?

geo $allowed {
 10.0.3.1 allow;
 10.0.2.0/24 allow;
 10.0.3.0/24 allow;
 default deny;
}

See this document for details.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.