# Nginx proxy\_pass + 10mbit traffic with syn, cache only image

**URL:** <https://www.ruby-forum.com/t/nginx-proxy-pass-10mbit-traffic-with-syn-cache-only-image/184941>\
**Category:** NGINX\
**Created:** [March 10, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/nginx-proxy-pass-10mbit-traffic-with-syn-cache-only-image/184941 "2010-03-10T18:19:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mayday](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ad7895/32.png) [@mayday](https://www.ruby-forum.com/u/mayday)\
**Post date:** [March 10, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/nginx-proxy-pass-10mbit-traffic-with-syn-cache-only-image/184941/1 "2010-03-10T18:19:12Z")

</div>

Hi, communtiy.

Maybe you can help solve my problem.  
I’m using nginx to proxify different request to dozens of backends.

I encountered such problem:  
If I enable caching in nginx, during high incoming requests (it seems  
~100 req/sec) some responses failed to cache (more often it’s css  
styles, which i can easily see is missing)

I suppose this is due to following reason:  
Request goes to the backend, but due to high network load response from  
backend lost somewhere in timeouts or network buffers in kernel. Then,  
when another requests comes, nginx think, it have this file cached on  
hdd, but fails and returns blank response. That causes some images and  
styles from webpages to disappear.

This is a part from global conf file which i believe can influence on  
this:

client\_header\_timeout 3m;  
client\_body\_timeout 3m;  
send\_timeout 3m;  
large\_client\_header\_buffers 40 20k;  
output\_buffers 1 32k;  
postpone\_output 1460;  
sendfile on;  
tcp\_nopush on;  
tcp\_nodelay on;  
keepalive\_timeout 0;  
reset\_timedout\_connection on;

Any my proxy location looks like  
location / {  
proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass\_header Set-Cookie;  
proxy\_pass\_header P3P;  
proxy\_pass http://@PROXY\_IP@/  
}

After this i thought: ok, it would be nice to cache only that images and  
proxify all other request direct to backend, but how should i configure  
cache to store only image files, to be sure to avoid any caching of  
dynamic pages and problems with such items like cached shopping cart or  
cached dynamic information on home page?

I’ve tried to install different location like ~ .+(.jpg|jpeg) and so on,  
but conftest failed with reason “i can’t do proxy pass in location,  
which contains regexp”. I found a solution with proxy\_store  
/tmp$original\_uri and then with handling error\_page 404 to some other  
location with proxy pass to backend somewhere on this forum, or on  
Igor’s website. But it seems to me, this is not the best solution. First  
of all i aware of cycling “error 404” request if this image are not  
avaible even on backend. Also, it seems this is not the direct way to  
cache static files.

Thank you.
