# Limit request + whitelist = not using response code from backend? 0.8.54

**URL:** <https://www.ruby-forum.com/t/limit-request-whitelist-not-using-response-code-from-backend-0-8-54/226725>\
**Category:** NGINX\
**Created:** [February 19, 2013, 2:06pm UTC](https://www.ruby-forum.com/t/limit-request-whitelist-not-using-response-code-from-backend-0-8-54/226725 "2013-02-19T14:06:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DreamWerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb9ed0/32.png) [@DreamWerx](https://www.ruby-forum.com/u/DreamWerx)\
**Post date:** [February 19, 2013, 2:06pm UTC](https://www.ruby-forum.com/t/limit-request-whitelist-not-using-response-code-from-backend-0-8-54/226725/1 "2013-02-19T14:06:33Z")

</div>

Hi all,

I’m hoping someone can help me with a small issue. I’m trying to  
implement rate limiting with a whitelist, and all in all it seems to  
be working, but  
the wrong response code is being sent back to the browser.

For example if the apache backend sends a 302 redirect response, nginx  
still sends a 200 back? If I remove the mapping to code 200, it then  
sends a 418 back.  
Is there an easy fix for this?

Here is my config. Thanks for any help.

* * *

http {  
recursive\_error\_pages on;  
proxy\_buffering off;

geo $limited {  
default 1;  
10.0.0.0/8 0;  
xxx.xxx.xxx.xx 0;  
}

limit\_req\_zone $binary\_remote\_addr zone=protect1:10m rate=5r/s;  
}

location / {  
error\_page 418 =200 @limitclient;  
#error\_page 418 @limitclient;  
if ($limited) {  
return 418;  
}

proxy\_read\_timeout 300;  
default\_type text/html;  
charset utf-8;  
proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_redirect off;  
proxy\_pass [http://backend](http://backend);  
}

location @limitclient {  
error\_page 503 @flooder;  
limit\_req zone=protect1 burst=5 nodelay;

proxy\_read\_timeout 300;  
default\_type text/html;  
charset utf-8;  
proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_redirect off;  
proxy\_pass [http://backend](http://backend);  
}

location @flooder {  
rewrite ^(.\*)$ /flooder.html break;  
}

---

<div class="post-metadata">

**Author:** ![DreamWerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb9ed0/32.png) [@DreamWerx](https://www.ruby-forum.com/u/DreamWerx)\
**Post date:** [February 19, 2013, 2:18pm UTC](https://www.ruby-forum.com/t/limit-request-whitelist-not-using-response-code-from-backend-0-8-54/226725/2 "2013-02-19T14:18:49Z")

</div>

Hello!

On Tue, Feb 19, 2013 at 02:05:46PM +0100, DreamWerx wrote:

> Is there an easy fix for this?  
> Yes,

- error\_page 418 =200 @limitclient;

- error\_page 418 = @limitclient;

See [Module ngx\_http\_core\_module](http://nginx.org/r/error_page).

Alternatively, you may want to use something like

```
geo $limited { ... }

map $limited $address {
    1 $binary_remote_address;
    0 "";
}

limit_req_zone $address zone=...;

```

to implement a whitelist (i.e., make sure the variable used in  
limit\_req\_zone is empty if you don’t want the limit).

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![DreamWerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb9ed0/32.png) [@DreamWerx](https://www.ruby-forum.com/u/DreamWerx)\
**Post date:** [February 19, 2013, 2:35pm UTC](https://www.ruby-forum.com/t/limit-request-whitelist-not-using-response-code-from-backend-0-8-54/226725/3 "2013-02-19T14:35:11Z")

</div>

Worked perfect! Thanks again.
