Allow caching of *some* filetypes?

mevans336 nginx-forum at forum.nginx.org
Thu Dec 22 13:24:13 UTC 2016


For security purposes, we utilize the Cache-Control "no-cache, no-store,
must-revalidate" add_header parameter in our root location block.

However, I'd like to tweak this to allow the following file types to be
cached: jpg|jpeg|png|gif|ico|js|css|html

I added this above my root location / block, but it breaks all images and
our css as well.

       location ~*  \.(jpg|jpeg|png|gif|ico|js|css|html)$ {
          expires 7d;
       }

Here is our root location block also:

 location / {

                add_header              X-Frame-Options SAMEORIGIN;
                add_header              Strict-Transport-Security
max-age=63072000;
                add_header              Cache-Control "no-cache, no-store,
must-revalidate";
                add_header              Pragma "no-cache";
                proxy_set_header        Host $host;
                proxy_http_version      1.1;
                proxy_set_header        Connection "";
                proxy_read_timeout      120s;
                proxy_next_upstream     error timeout invalid_header
http_404 http_500;
                proxy_intercept_errors  on;
                proxy_pass              http://my_proxy;
}

Am I doing this correctly?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,271676,271676#msg-271676



More information about the nginx mailing list