禁用NGINX缓存后,使浏览器客户端刷新缓存的内容

时间:2019-03-11 12:39:48

标签: nginx browser-cache nginx-reverse-proxy

由于某种原因,某个网站的某些浏览器客户端确实获得了该网站的“错误”版本,从而在页面(内置于Angular)中出现了一些错误。一切都在NGINX Docker化的网络服务器后面-所有站点都是docker容器。

当我从浏览器检查呼叫时,我可以看到内容具有一年的最大标头,因此我决定专门针对导致该错误序列的JSON内容删除该标头。以前它具有以下标头:

strict-transport-security: max-age=31536000

在我删除的回复中。现在我拥有的NGINX配置有了这个模板:

location / {
                proxy_buffers         8 16k;  # Buffer pool = 8 buffers of 16k  
                proxy_buffer_size     16k;    # 16k of buffers from pool used for headers 
                {{ if eq $proto "uwsgi" }}
                include uwsgi_params;
                uwsgi_pass {{ trim $proto }}://{{ trim $host }};
                {{ else }}
                proxy_pass {{ trim $proto }}://{{ trim $host }};
                {{ end }}
                {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
                auth_basic      "Restricted {{ $host }}";
                auth_basic_user_file    {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
                {{ end }}
                {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
                include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
                {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
                include /etc/nginx/vhost.d/default_location;
                {{ end }}
                add_header Last-Modified $date_gmt;
                add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
                if_modified_since off;
                expires off;
                etag off;
        }

        location ~* ^.+\.(atom|bmp|bz2|css|doc|docx|eot|exe|gif|gz|ico|jpeg|jpg|js|mid|midi|mp4|ogg|ogv|otf|pdf|png|ppt|pptx|rar|rss|rtf|svg|svgz|swf|tar|tgz|ttf|txt|wav|woff|xls|xml|zip)$ {
                expires max;
                {{ if eq $proto "uwsgi" }}
                include uwsgi_params;
                uwsgi_pass {{ trim $proto }}://{{ trim $host }};
                {{ else }}
                proxy_pass {{ trim $proto }}://{{ trim $host }};
                {{ end }}
                {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
                auth_basic      "Restricted {{ $host }}";
                auth_basic_user_file    {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
                {{ end }}
                {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
                include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
                {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
                include /etc/nginx/vhost.d/default_location;
                {{ end }}
        }

我确实添加了删除缓存的位:

add_header Last-Modified $date_gmt;
                add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
                if_modified_since off;
                expires off;
                etag off;

但是,对于已经加载了网站的手机来说,这并没有什么不同。我试图创建一个全新版本的Web文件,为文件名生成新的哈希值以强制刷新,但似乎不起作用。

有没有办法让当前的“损坏”移动页面重新加载内容并强制新数据通过?

谢谢!

0 个答案:

没有答案