Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I see indications that this should work, so I'm hoping I'm missing something simple.

We have two nginx "servers", a proxy_pass cache in front and an SSI server behind it. If I go directly to the SSI server with an If-Modified-Since header in the request, it will return a 304-Not Modified response just fine, which is what we want. But I cannot get the proxy_pass cache server to return a 304-Not Modified for anything.

Should I be able to get the proxy_pass to return a 304-Not Modified? Does anyone else have it working with a config you could share? Or can you spot the problem in my config?

# this is the cache in front
server {
    listen 8096;    
    server_name _;
    proxy_buffering on;

    location /assets {
        proxy_pass http://localhost:8095;
        proxy_cache   my-cache;
        proxy_cache_valid  200s;
        if_modified_since before;
    }       
}

server {
    listen 8095;
    server_name _;
    root /var/www/;
    location / { deny all; }

    location /assets {}
        ssi on; # on or off doesn't make a difference to the front-end cache behavior
        if_modified_since before;   
    }
}

# here's the base config, fwiw:
proxy_buffering         on;
proxy_cache_valid       any 10m;
proxy_cache_path        /var/cache/nginx levels=1:2 keys_zone=my-cache:8m max_size=3000m inactive=24h;
proxy_temp_path         /var/cache/nginx/tmp;
proxy_buffer_size       4k;
proxy_buffers           100 8k;

Thanks.

share|improve this question
    
With proxy_cacheenabled, the request will not be proxied to the upstream server when the cache is hit. However, in order for your upstream server to return a 304, you'll want to send the if_modified_since header along with the request. Try out proxy_set_header If-Modified-Since $http_if_modified_since. –  Andrew Ty. Apr 18 '13 at 17:28
    
It's actually the downstream server I wanted to return a 304. But your comment got me heading in the right direction--I found nginx had cached an Expires header from a previous test that was off into next week. So yes, it works with my config, thanks! –  Kevin G. Apr 18 '13 at 18:28

1 Answer 1

Yes it's possible, and yes this config works fine. Turns out nginx was caching an Expires header set to next week from my testing. Never Mind :-/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.