# Can't cache javascript file from proxy

**URL:** <https://www.ruby-forum.com/t/cant-cache-javascript-file-from-proxy/242919>\
**Category:** NGINX\
**Created:** [August 7, 2015, 1:13pm UTC](https://www.ruby-forum.com/t/cant-cache-javascript-file-from-proxy/242919 "2015-08-07T13:13:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 7, 2015, 1:13pm UTC](https://www.ruby-forum.com/t/cant-cache-javascript-file-from-proxy/242919/1 "2015-08-07T13:13:06Z")

</div>

Hi,

I have a problem with cache javascript file from a proxy glassfish4.0  
Server.

My nginx.conf is this:

* * *

user nginx nginx;  
error\_log /var/log/nginx/error.log warn;  
pid /usr/local/nginx/logs/nginx\_1.8.0.pid;  
worker\_processes auto;  
worker\_rlimit\_nofile 1024;  
worker\_priority -5;  
worker\_cpu\_affinity 01 10;

events {

```
    worker_connections 128;
    multi_accept on;
    use epoll;
    #debug_connection 127.0.0.1;
    debug_connection 10.77.37.133;

```

}

* * *

And this is my specific site conf file  
http {

```
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 65;
    reset_timedout_connection on;
    log_not_found off;
    proxy_cache_path /tmp/nginx/cache keys_zone=cache1:10m;
    proxy_cache_valid 200 302 8h;

    server {

            listen 81;
            server_name r60;
            root /var/nginx/first/html;

            set $cache_key "$request_uri";

            location / {

                    index index.html index.htm;

            }

            error_page 500 502 503 504 /50x.html;
            error_page 404 =200 /50x.html;
            error_page 403 =200 /50x.html;
            location = /50x.html {
                    root html;
            }

            location /site
            {
                    location ~* \.(js)$
                    {
                    proxy_cache cache1;
                    proxy_cache_key $cache_key;
                    proxy_ignore_headers "Cache-Control";
                    #proxy_ignore_headers "Pragma";
                    proxy_hide_header Cache-Control;
                    proxy_hide_header Pragma;
                    add_header X-Proxy-Cache $upstream_cache_status;
                    proxy_pass http://10.77.38.166:8080;
                    }

                    proxy_pass http://10.77.38.166:8080;
            }

    }

```

}

* * *

I have no problem in configuration sintax (nginx -t → OK)

With a browser, I open a web page [http://r60:81/site](http://r60:81/site) and I see all the  
content of the page.  
This is OK but I don’t view anything in /tmp/nginx/cache (no cache  
files  
)

My web request download 3 javascript file.  
I expect it to be cached.

Why proxy\_ignore\_headers “Cache-Control” doesn’t work properly?

Thanks in advace

Posted at Nginx Forum:

> **[can't cache javascript file from proxy](https://forum.nginx.org/read.php?2,260847,260847#msg-260847)**
>
> Hi, I have a problem with cache javascript file from a proxy glassfish4.0 Server. My nginx.conf is this: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ user nginx nginx; error\_log /var/log/nginx/error.log warn; pid

---

<div class="post-metadata">

**Author:** ![bugster86](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f9ae1b/32.png) [@bugster86](https://www.ruby-forum.com/u/bugster86)\
**Post date:** [August 7, 2015, 8:18pm UTC](https://www.ruby-forum.com/t/cant-cache-javascript-file-from-proxy/242919/2 "2015-08-07T20:18:24Z")

</div>

Hello!

On Fri, Aug 07, 2015 at 07:12:21AM -0400, bugster86 wrote:

> Hi,
> 
> I have a problem with cache javascript file from a proxy glassfish4.0  
> Server.

[…]

> ```
> proxy_ignore_headers "Cache-Control";
> #proxy_ignore_headers "Pragma";
> 
> ```

[…]

> With a browser, I open a web page [http://r60:81/site](http://r60:81/site) and I see all the  
> content of the page.  
> This is OK but I don’t view anything in /tmp/nginx/cache (no cache files  
> )
> 
> My web request download 3 javascript file.  
> I expect it to be cached.
> 
> Why proxy\_ignore\_headers “Cache-Control” doesn’t work properly?

There are other headers in addition to Cache-Control which may  
prevent caching of a response by nginx. Most notably, Expires and  
Set-Cookie. Check if the response contains them to see if it’s  
the case.

See [Module ngx\_http\_proxy\_module](http://nginx.org/r/proxy_ignore_headers) for a full list.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![bugster86](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f9ae1b/32.png) [@bugster86](https://www.ruby-forum.com/u/bugster86)\
**Post date:** [August 8, 2015, 1:36pm UTC](https://www.ruby-forum.com/t/cant-cache-javascript-file-from-proxy/242919/3 "2015-08-08T13:36:28Z")

</div>

Thank you Maxim.

I added these 2 directives in my configuration file:

proxy\_ignore\_headers “Expires”;  
proxy\_ignore\_headers “Set-Cookie”;

And now my cache folder has some file !!!

[root@puppet cache]# ls  
0741765da3f800afaeeca0c3a6139db8 0cbfc19bd25e83d6ffa73641383bab4a  
a5d938d8984466ebe2e9894c65ef49f1

Posted at Nginx Forum:

> **[Re: can't cache javascript file from proxy](https://forum.nginx.org/read.php?2,260847,260880#msg-260880)**
>
> Hi, I have a problem with cache javascript file from a proxy glassfish4.0 Server. My nginx.conf is this: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ user nginx nginx; error\_log /var/log/nginx/error.log warn; pid
