# Bug in limit\_req

**URL:** <https://www.ruby-forum.com/t/bug-in-limit-req/217572>\
**Category:** NGINX\
**Created:** [March 5, 2012, 4:35pm UTC](https://www.ruby-forum.com/t/bug-in-limit-req/217572 "2012-03-05T16:35:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 5, 2012, 4:35pm UTC](https://www.ruby-forum.com/t/bug-in-limit-req/217572/1 "2012-03-05T16:35:01Z")

</div>

Hello,

limit\_req does not work with Nginx 1.1.16 - if used on different  
levels.  
`for a in `seq 300`; do wget -O /dev/null http://localhost:8081/; done`  
Exepected result: 503, result is always “502 bad gateway”.  
Down below the config file.

Thanks a lot

error\_log /tmp/nginx-error\_log info;  
pid /tmp/nginx.pid;  
events {  
worker\_connections 65535;  
}

http {  
default\_type application/octet-stream;

```
limit_req_zone $binary_remote_addr

```

zone=everything\_ip:32m rate=50r/s;  
limit\_req zone=everything\_ip burst=50;

```
limit_req_zone $binary_remote_addr zone=fastcgi_ip:32m

```

rate=2r/s;

```
server {
    listen *:8081;
    root /tmp/www;

    # fastcgi
    location @backend {
        limit_req zone=fastcgi_ip burst=10;
        fastcgi_pass unix:/tmp/nginx.dispatch.sock;
    }

    # static
    location / {
        try_files $uri @backend;
        expires max;
    }
}

```

}

Posted at Nginx Forum:

> **[bug in limit\_req](https://forum.nginx.org/read.php?2,223426,223426#msg-223426)**
>
> Hello, limit\_req does not work with Nginx 1.1.16 - if used on different levels. \`for a in \`seq 300\`; do wget -O /dev/null http://localhost:8081/; done\` Exepected result: 503, result is always "502 bad gateway". Down below the config file.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 5, 2012, 5:01pm UTC](https://www.ruby-forum.com/t/bug-in-limit-req/217572/2 "2012-03-05T17:01:10Z")

</div>

Hello!

On Mon, Mar 05, 2012 at 10:34:01AM -0500, double wrote:

> limit\_req does not work with Nginx 1.1.16 - if used on different  
> levels.  
> `for a in `seq 300`; do wget -O /dev/null http://localhost:8081/; done`  
> Exepected result: 503, result is always “502 bad gateway”.  
> Down below the config file.

[…]

> http {

[…]

> ```
> limit_req_zone $binary_remote_addr zone=everything_ip:32m 
> 
> ```

rate=50r/s;

> ```
> limit_req zone=everything_ip burst=50;
> 
> limit_req_zone $binary_remote_addr zone=fastcgi_ip:32m 
> 
> ```

rate=2r/s;

> ```
> server {
> 
> ```

[…]

> ```
> }
> }
> 
> ```
> 
> }

With such configuration the “limit\_req zone=everything\_ip  
burst=50;” as specified on http level will be used to limit  
requests (it’s inherited into “location /” and checked there  
before try\_file; the limit\_req directive in @backend location  
isn’t checked as we’ve already checked limit\_req limits).

Furthermore, as the directive doesn’t have the “nodelay”  
argument, it’s not expected to overflow the burst (and return 503)  
if there is only single process doing requests (as in the sh  
snippet above).

That is, there is no bug here. Probably there is a room for  
improvement though, as currently separate limiting of a location  
after try\_files is only possible if there were no limits in the  
location with try\_files.

Maxim D.
