Can't cache javascript file from proxy

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 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:

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 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 for a full list.


Maxim D.
http://nginx.org/

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: