Dynamic Cache in Nginx

Maxim Dounin mdounin at mdounin.ru
Wed Aug 8 10:37:23 UTC 2012


Hello!

On Tue, Aug 07, 2012 at 04:23:25PM -0400, TiagoCruz wrote:

> Hello guys,
> 
> I'm trying to set some Expires in a lot of JavaScript that I got here,
> but they are not static on filesystem, it is dynamic generated by a Java
> application.
> 
> If I do this:
> 
> ===================
>   location /bla {
>     root /tmp;
>     expires 30m;
>     }
> ===================
> 
> And put some .js files inside /tmp/bla everything works fine.
> 
> But when I try to do this:
> 
> ===================
>  location /script {
>    expires 30m;
>     proxy_cache             cache;
>     proxy_pass              http://localhost:8080;
>     proxy_set_header        X-Real-IP $remote_addr;
>     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
>     proxy_set_header        Host $http_host;
>   }
> ===================
> 
> Does not work. The reply from the server is always 200, never 304  as it
> should be.
> 
> What can I do to fix this? 
> 
> I also tried to use nginx 1.3.3 with Etag support, but also only works
> with static files :(

For conditinal requests to work (and 304 to be returned) you need 
Last-Modified (and/or ETag) header in original response.  Try 
adding one in your application.

Maxim Dounin



More information about the nginx mailing list