Hello!
We recently started using Nginx 0.7.59 to replace Squid on a couple of
our
static file caching servers (Debian 5.0). However, nginx is returning
“HTTP
304 Not Modified” responses for some—not all—of the cached images, even
if
the browser doesn’t send an If-modified-since header – causing lots of
broken images when viewing the site in browser.
As soon as I turn off the “proxy_cache” directive and let the requests
be
proxied to the upstream server, bypassing nginx’s cache, no more
unexpected
304’s are served, and the broken images disappear.
Do you have any idea of what might be causing this problem?
My nginx.conf file is below:
worker_processes 3;
error_log logs/error.log;
events {
worker_connections 10240;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
keepalive_timeout 10;
gzip on;
upstream backend {
server xxx.xxx.xxx.xxx;
}
proxy_buffer_size 16k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 32k;
proxy_intercept_errors on;
proxy_cache_path /var/www/cache levels=1:2
keys_zone=zone_one:10m inactive=24h;
server {
listen 80;
server_name localhost;
location / {
proxy_cache zone_one;
proxy_cache_valid 200 7d;
proxy_pass http://backend;
}
}
}
I added the “proxy_cache_valid” directive to only cache 200 responses,
but
that didn’t seem to change anything (even after deleting the cache).
This is pretty much what I’m seeing:
$ curl -I
http://www.myserver.com/thumbs/125x100/10081/m88_1240816236.jpg
HTTP/1.1 304 Not Modified
Server: nginx/0.7.59
Date: Mon, 08 Jun 2009 09:26:05 GMT
Connection: keep-alive
Last-Modified: Mon, 27 Apr 2009 07:10:40 GMT
Expires: Wed, 08 Jul 2009 08:19:13 GMT
Cache-Control: max-age=2592000
If I disable the proxy_cache (leaving just proxy_pass in location /):
$ curl -I
http://www.myserver.com/thumbs/125x100/10081/m88_1240816236.jpg
HTTP/1.1 200 OK
Server: nginx/0.7.59
Date: Mon, 08 Jun 2009 09:28:17 GMT
Content-Type: image/jpeg
Connection: keep-alive
Content-Length: 3869
Last-Modified: Mon, 27 Apr 2009 07:10:40 GMT
Vary: Accept-Encoding
Expires: Wed, 08 Jul 2009 09:32:33 GMT
Cache-Control: max-age=2592000
Accept-Ranges: bytes
I’m not quite sure where to start debugging this. Does anyone have any
advice?
Thanks,
Antonio