# How to cache the directory index, but not the content of it

**URL:** <https://www.ruby-forum.com/t/how-to-cache-the-directory-index-but-not-the-content-of-it/188169>\
**Category:** NGINX\
**Created:** [May 6, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/how-to-cache-the-directory-index-but-not-the-content-of-it/188169 "2010-05-06T20:44:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mihaimustea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mihaimustea](https://www.ruby-forum.com/u/mihaimustea)\
**Post date:** [May 6, 2010, 8:44pm UTC](https://www.ruby-forum.com/t/how-to-cache-the-directory-index-but-not-the-content-of-it/188169/1 "2010-05-06T20:44:57Z")

</div>

Hello,

I hope I won’t ask a Mickey M. question, but I searched on the web  
and found nothing. Here is what I need to cache. Below is a summary of  
the tree of the website that I’m trying to cache:

/shop - i want to cache only the page requested like this (i cannot ask  
for index.php)  
/shop/page.html - don’t want to cache  
/shop/dir - don’t want to cache  
/shop/dir/page.html - don’t want to cache  
/shop/img/\*.(png|jpg|gif|css|js) - cache all static content (this i made  
it)  
/shop/account/ - don’t cache  
/shop/account/login - cache (this i made it)

This is not actually the tree, but i have something like this. I tried  
different configurations, but none work (my main concern is to cache  
/shop because 50% of the hits are there). Can you please give me a hint?  
I’m not asking for the whole solution, just a hint. Probably there are  
some other guys looking for something like this and cannot find it (like  
me).

Below, you can find the part of the config that it’s working at the  
moment:

* * *

location ~\* ^.\*.(jpg|png|css|js|gif)$ {

```
  proxy_pass http://www.example.ro;
  proxy_cache example-images;

  include conf/proxy_general.conf;

```

}

location /shop/customer/account/login/ {

```
  proxy_pass http://www.example.ro/shop/customer/account/login/;
  proxy_cache example-login;

  include conf/proxy_general.conf;

```

}

location /shop/ {

```
  proxy_pass http://www.example.ro/;
  proxy_cache example-shop;

  include conf/proxy_general.conf;

```

}

location / {

```
  proxy_pass http://www.example.ro;

  include conf/proxy_general.conf;

```

}

* * *

and proxy\_general.conf:

* * *

proxy\_ignore\_headers “Cache-Control” “Expires”;

proxy\_cache\_valid 200 302 10m;

```
    proxy_redirect off;

```

proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_max\_temp\_file\_size 0;

```
    client_max_body_size 100m;
    client_body_buffer_size 128k;

    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;

    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

```

proxy\_cache\_use\_stale error timeout invalid\_header updating http\_500  
http\_502 http\_503 http\_504;

* * *

Thank you,

Mihai.

Posted at Nginx Forum:

> **[How to cache the directory index, but not the content of it](https://forum.nginx.org/read.php?2,83458,83458#msg-83458)**
>
> Hello, I hope I won't ask a Mickey Mouse question, but I searched on the web and found nothing. Here is what I need to cache. Below is a summary of the tree of the website that I'm trying to cache: /shop - i want to cache only the page requested like...

---

<div class="post-metadata">

**Author:** ![mihaimustea](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/46a35a/32.png) [@mihaimustea](https://www.ruby-forum.com/u/mihaimustea)\
**Post date:** [May 6, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/how-to-cache-the-directory-index-but-not-the-content-of-it/188169/2 "2010-05-06T21:20:05Z")

</div>

I think I fixed it. If someone needs it:

* * *

location ~ /shop(/.\*) {

```
  proxy_pass http://www.example.ro;
  include conf/proxy_general.conf;

```

## }

If there is a more elegant way, please reply.

Thanks.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,83458,83486#msg-83486](http://forum.nginx.org/read.php?2,83458,83486#msg-83486)
