# Dynamic Cache in Nginx

**URL:** <https://www.ruby-forum.com/t/dynamic-cache-in-nginx/221974>\
**Category:** NGINX\
**Created:** [August 7, 2012, 10:23pm UTC](https://www.ruby-forum.com/t/dynamic-cache-in-nginx/221974 "2012-08-07T22:23:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 7, 2012, 10:23pm UTC](https://www.ruby-forum.com/t/dynamic-cache-in-nginx/221974/1 "2012-08-07T22:23:52Z")

</div>

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](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 ☹

Thanks!!

Posted at Nginx Forum:

> **[Dynamic Cache in Nginx](https://forum.nginx.org/read.php?2,229409,229409#msg-229409)**
>
> 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;

---

<div class="post-metadata">

**Author:** ![TiagoCruz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/59ef9b/32.png) [@TiagoCruz](https://www.ruby-forum.com/u/TiagoCruz)\
**Post date:** [August 8, 2012, 12:37pm UTC](https://www.ruby-forum.com/t/dynamic-cache-in-nginx/221974/2 "2012-08-08T12:37:49Z")

</div>

Hello!

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

> ```
> root /tmp;
> 
> ```
> 
> expires 30m;
> 
> 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 D.
