Nginx unexpectedly returning 304 for content cached from proxy
Igor Sysoev
is at rambler-co.ru
Mon Jun 8 14:26:53 MSD 2009
On Mon, Jun 08, 2009 at 01:39:12PM +0400, Antonio L. wrote:
> 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;
> }
> }
> }
> ###
This is a bug. I will try to fix in today 0.8.1.
As quick workaround, you may set any proxy_set_header directive in
cached location, e.g.:
location / {
proxy_cache zone_one;
proxy_cache_valid 200 7d;
proxy_pass http://backend;
+ proxy_set_header Host backend;
}
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list