解决加载静态文件无法被浏览器缓存问题

开发环境是:nginx+spring boot + thymeleaf.
遇到的问题:js/css等静态资源文件不被浏览器缓存;如果是本地开发环境不会有这个问题。
解决方法是:nginx设置gzip和过期时间
 
nginx设置gzip:nginx.conf
gzip    on;   
gzip_comp_level  6;    # 压缩比例,比例越大,压缩时间越长。默认是1  
gzip_types    text/xml text/plain text/css application/javascript application/x-javascript application/rss+xml;     # 哪些文件可以被压缩   
gzip_disable    "MSIE [1-6].";     # IE6无效
 
nginx设置过期时间
server {
    listen       443 ssl;
    server_name  yy.domain.com;
 
    ssl_certificate      /usr/local/tomcatInstance/assistAdmin/cert/1.pem;
    ssl_certificate_key  /usr/local/tomcatInstance/assistAdmin/cert/1.key;
 
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  5m;
 
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
 
    location ~* .(ico|gif|bmp|jpg|jpeg|png|swf|js|css) {
        proxy_pass https://yy;
        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;
        expires 30d;
    }
}
原文地址:https://www.cnblogs.com/zhutouying/p/7484060.html