# Nginx proxy\_intercept\_errors

**URL:** <https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179>\
**Category:** NGINX\
**Created:** [March 6, 2013, 2:45pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179 "2013-03-06T14:45:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 2:45pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/1 "2013-03-06T14:45:38Z")

</div>

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 2:54pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/2 "2013-03-06T14:54:25Z")

</div>

Hello!

On Wed, Mar 06, 2013 at 03:44:37PM +0200, Kiril Kalchev wrote:

> I have noticed that when I set ‘proxy\_intercept\_errors on;’ in  
> my nginx config it kills tcp connection to the origin server if  
> it returns 4xx or 5xx?  
> This is my example config to reproduce the  
> situation([https://gist.github.com/kirilkalchev/5098882](https://gist.github.com/kirilkalchev/5098882)). I am  
> in a situation where my backend server returns only 403 and 404  
> (it is some kind of home made authentication system 403 means go  
> away 404 means continue) and I need to display different things  
> in this cases, but without keep alive connections to the backend  
> are exhausted pretty fast.

With proxy\_intercept\_errors nginx doesn’t read the response body  
if a response returned is the error, and the upstream connection  
can’t be kept alive due to this (unless there is no body and it’s  
known after reading response headers).

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 3:03pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/3 "2013-03-06T15:03:11Z")

</div>

Is there any way to force nginx to read request body? I really don’t  
care about this overhead, I hit connection limit much more faster. Thank  
you for the super fast answer.

Regards,  
Kiril

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 3:32pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/4 "2013-03-06T15:32:24Z")

</div>

Hello!

On Wed, Mar 06, 2013 at 04:02:30PM +0200, Kiril Kalchev wrote:

> Is there any way to force nginx to read request body? I really  
> don’t care about this overhead, I hit connection limit much more  
> faster. Thank you for the super fast answer.

No, there is no way to force nginx to read response body - errors  
interception happens right after reading response headers and  
before the body is read. (Well, you may configure another proxy  
layer without intercept errors, but this probably doesn’t counts  
as a real solution to what you are trying to do.)

On the other hand, if you have only 403/404 responses you want to  
intercept - you may force your backend to return only headers by  
using

```
proxy_method HEAD;

```

in your config (see [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_method)).

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 3:46pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/5 "2013-03-06T15:46:26Z")

</div>

Just for the record, I think I found a kind of solution. It looks good  
if my backend returns http codes 3xx. I have tried with 333 and 334 and  
it looks great. I know it is an ugly hack, but my findings may help to  
other poor souls. I hope this behavior will not change in the next  
versions.

Regards,  
Kiril

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 4:44pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/6 "2013-03-06T16:44:18Z")

</div>

Hello!

On Wed, Mar 06, 2013 at 04:45:33PM +0200, Kiril Kalchev wrote:

> Just for the record, I think I found a kind of solution. It  
> looks good if my backend returns http codes 3xx. I have tried  
> with 333 and 334 and it looks great. I know it is an ugly hack,  
> but my findings may help to other poor souls. I hope this  
> behavior will not change in the next versions.

I would suppose it works as these responses are returned with  
“Content-Length: 0” by your backend. As already mentioned in the  
very first reply, connections are kept alive if it’s known from  
response headers that there is no body.

–  
Maxim D.  
[http://nginx.org/en/donation.html](http://nginx.org/en/donation.html)

---

<div class="post-metadata">

**Author:** ![Kiril\_Kalchev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ad7895/32.png) [@Kiril\_Kalchev](https://www.ruby-forum.com/u/Kiril_Kalchev)\
**Post date:** [March 6, 2013, 4:55pm UTC](https://www.ruby-forum.com/t/nginx-proxy-intercept-errors/227179/7 "2013-03-06T16:55:59Z")

</div>

Yes you are right. Thank you.
