# Nginx-1.4 proxy requests being continious

**URL:** <https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825>\
**Category:** NGINX\
**Created:** [May 9, 2013, 2:39am UTC](https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825 "2013-05-09T02:39:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8edcca/32.png) [@Daniel\_Black](https://www.ruby-forum.com/u/Daniel_Black)\
**Post date:** [May 9, 2013, 2:39am UTC](https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825/1 "2013-05-09T02:39:43Z")

</div>

A request for /img/file\_doesnt\_exist.jpg results in the backend server  
(192.168.129.90) getting continuous requests for the same file (which  
doesn’t exist there either so 404 each time), while the original  
requester waits and nginx keeps asking the backend the same.

I’m using the nginx-1.4.1 from the debian squeeze repository.

Is there a better way do to this config? The aim for for all web servers  
to have the same config so a resource that aren’t synced yet still get  
served a response if it exists somewhere but without the requests ending  
up in a circular loop.

My current, hopefully not too cut down, config is:

upstream imgweb\_other {  
server 192.168.129.90;  
server 173.230.136.6 backup;  
}

server {

proxy\_read\_timeout 15;  
proxy\_connect\_timeout 3;  
proxy\_next\_upstream error timeout invalid\_header http\_500 http\_502  
http\_503 http\_504 http\_404;

location ~ ^/img/(.\*)  
{  
expires 2592000;  
add\_header Cache-Control public;  
alias /var/www/live\_site\_resources/$1;  
error\_page 404 = @imgweb\_other;  
}

location @imgweb\_other {  
# we only want to fallback once so use user\_agent as a flag  
if ( $http\_user\_agent = IMGWEB ) {  
return 404;  
}  
proxy\_pass http://imgweb\_other;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header User-Agent IMGWEB;  
}

}

---

<div class="post-metadata">

**Author:** ![Daniel\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8edcca/32.png) [@Daniel\_Black](https://www.ruby-forum.com/u/Daniel_Black)\
**Post date:** [May 11, 2013, 8:14am UTC](https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825/2 "2013-05-11T08:14:34Z")

</div>

Just to prove I’m not making it up (even though I’m having a hard time  
replicating it).

log\_format extended '$remote\_addr - $remote\_user [$time\_local] ’  
'“$request” $status $request\_time $body\_bytes\_sent ’  
‘$upstream\_cache\_status $upstream\_addr  
$upstream\_status $upstream\_response\_time’  
‘“$http\_referer” “$http\_user\_agent”’;

length of log line 3412217 characters (is that a record?)  
58.169.18.35 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.1” 499 100.820 0 -  
192.168.  
129.90:80, 192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80,  
192.168.129.90:80, 192.168.129.90:80, 192.168.129.90:80 (many many  
pages)… 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404,  
404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404,  
404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404,  
404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404,  
404…, - 0.014, 0.001, 0.000, 0.001, 0.001, 0.000, 0.001,  
0.001, 0.000, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001.. , - “-”  
“Wget/1.13.4 (linux-gnu)”

192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
“IMGWEB”  
192.168.131.254 - - [08/May/2013:19:58:13 -0400] “GET  
//img/covers/medium/587/9781844454581.jpg HTTP/1.0” 404 0.000 169 “-”  
"IMGWEB

----- Original Message -----

> requests ending up in a circular loop.  
> proxy\_read\_timeout 15;  
> }  
> proxy\_set\_header User-Agent IMGWEB;  
> }
> 
> }
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

## –

Daniel Black, Engineer @ Open Query ([http://openquery.com](http://openquery.com))  
Remote expertise & maintenance for MySQL/MariaDB server environments.

---

<div class="post-metadata">

**Author:** ![Daniel\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8edcca/32.png) [@Daniel\_Black](https://www.ruby-forum.com/u/Daniel_Black)\
**Post date:** [May 12, 2013, 1:43am UTC](https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825/3 "2013-05-12T01:43:39Z")

</div>

Hello!

On Sat, May 11, 2013 at 04:13:38PM +1000, Daniel Black wrote:

[…]

> > A request for /img/file\_doesnt\_exist.jpg results in the backend server  
> > (192.168.129.90) getting continuous requests for the same file (which  
> > doesn’t exist there either so 404 each time), while the original  
> > requester waits and nginx keeps asking the backend the same.
> > 
> > I’m using the nginx-1.4.1 from the debian squeeze repository.

[…]

> > server 173.230.136.6 backup;

[…]

> > proxy\_next\_upstream error timeout invalid\_header http\_500 http\_502  
> > http\_503 http\_504 http\_404;

What you describe looks very familiar - there was such a bug which  
manifested itself with backup servers and proxy\_next\_upstream  
http\_404. It was fixed in 1.3.0/1.2.1 though:

```
*) Bugfix: nginx might loop infinitely over backends if the
   "proxy_next_upstream" directive with the "http_404" parameter was
   used and there were backup servers specified in an upstream 

```

block.

Are you sure you are using 1.4.1 on your frontend (note: it’s  
usually not enough to check version of nginx binary on disk, as  
running nginx binary may be different)? Could you please provide  
frontend’s debug log?

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![Daniel\_Black](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8edcca/32.png) [@Daniel\_Black](https://www.ruby-forum.com/u/Daniel_Black)\
**Post date:** [May 12, 2013, 4:47am UTC](https://www.ruby-forum.com/t/nginx-1-4-proxy-requests-being-continious/228825/4 "2013-05-12T04:47:06Z")

</div>

Hi!

> used and there were backup servers specified in an upstream block.
> 
> Are you sure you are using 1.4.1 on your frontend (note: it’s  
> usually not enough to check version of nginx binary on disk, as  
> running nginx binary may be different)? Could you please provide  
> frontend’s debug log?

Quite right. I did update to 1.4.1 just afterwards.  
2013-05-08 20:16:29 upgrade nginx 0.7.67-3+squeeze3 1.4.1-1~squeeze

I definitely restarted the nginx-1.4.1 with no remnants of 0.7.67 around  
and haven’t had the troubles when I re-tested.

Thanks for the fix Maxim and digging up this changelog entry.

Looking forward to putting it into production in the next few hours. Any  
troubles and I will grab a debug log for you.

–  
Daniel Black
