4

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

1 Answer 1

7

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .