title: Multiple limit_req_zone with geo and map in nginx
body: <p>I need help in defining rate limiting in nginx usging map and geo modules.</p>
  
  <p>I've defined 4 cases with. Each of these cases should have a different rate limit set :</p>
  
  <pre><code>geo $limited_ip {
              default                 0;
              1.1.1.1/24              1;
              2.2.2.2/24              2;
              3.3.3.3/24              3;
      }
  </code></pre>
  
  <p>I use map module to transfer the ip value of the client to a variable :</p>
  
  <pre><code>map $limited_ip $limited_ip_key {
              0 '';
              1 $binary_remote_addr;
              2 $binary_remote_addr;
              3 $binary_remote_addr;
      }
  </code></pre>
  
  <p>Now, I set 4 limit zones. The last zone is for testing :</p>
  
  <pre><code>limit_req_zone $limited_ip_key zone=zone0:10m rate=100r/m;
  limit_req_zone $limited_ip_key zone=zone1:10m rate=200r/m;
  limit_req_zone $limited_ip_key zone=zone2:10m rate=500r/m;
  limit_req_zone $limited_ip_key zone=zone3:10m rate=1r/m;
  </code></pre>
  
  <p>Finally, I apply the limits in the server{} block :</p>
  
  <pre><code>limit_req zone=zone0 burst=10 nodelay;
  limit_req zone=zone1 burst=10 nodelay;
  limit_req zone=zone2 burst=10 nodelay;
  limit_req zone=zone3 burst=1 nodelay;
  </code></pre>
  
  <p>The configuration test if ok, I reload nginx, ok too. Using apache bench tool (ab) to hammer the nginx server, it looks like zone3 always match for any source IP. Why do IP from other masks defines by geo module matche zone3 ?</p>
  
  <p>Log :</p>
  
  <pre><code>*2757 limiting requests, excess: 1.697 by zone "zone3", client: 3.3.3.3, server: my.domain.com, request: "HEAD / HTTP/1.0", host: "my.domain.com"
  *29449 limiting requests, excess: 1.958 by zone "zone3", client: 2.2.2.2, server: my.domain.com, request: "HEAD / HTTP/2.0", host: "my.domain.com"
  </code></pre>
  
  <p>All results I found are about 2 zones defined, I can't find examples with more zones. Maybe it's not possible to do it this way ?</p>
  
  <p>Thank you</p>