I have web-application, and there is interface where I can refresh logo of a shop. When I refresh logo, I gеt new file with new last-modified
header:
Nginx returns corrected updated file.
After that I update logo again. But I get old logo with old last-modified
, although logo url file was changed (you can see query timestamp at the end of url):
If I perform direct request through browser, then I get updated file:
This can be seen in the file size via content-length.
My nginx config for images is:
location ~* ^.+\.(jpg|jpeg|svg|gif|png)$ {
expires 10d;
try_files $uri @app;
}
I don't understand what I'm doing wrong. Please, help me. Thanks in advance
There is not enough information to determine the root cause of the problem that's being experienced; I also imagine that all new folks that come to this question experience a slightly different problem that the one outlined above.
Nginx has http://nginx.org/r/if_modified_since directive, you can take a look at the source code of the implementation in ngx_http_not_modified_filter_module.c :: ngx_http_not_modified_header_filter().
In general, just because the URL has a changed epoch parameter (the ?
part with the UNIX time as a trailing slug), doesn't at all mean that a new resource has to be provided, so, to determine that nginx is wrong simply because the URL is different between the first two pics, yet Last-Modified
time is same, is not correct. Likewise, the final third pic lists a 304 Not Modified
response, yet there is no information about the If-Modified-Since
nor If-None-Match
headers in the response, and the attribution for the pic doesn't make any sense, either.
Based on my experience this is probably not a nginx-issue but a common browser-behavior.
Browsers might refresh the page itself if you force it, but file-links are not always populated and the files are served from the cache.
If I have to change files like images, stylesheets or script-files several times I open an extra tab, for the corresponding file and populate there first before the page which includes that file.
If you've server access, which has to be assumed as you mention nginx, it's possible to reduce the max-age
to a few seconds only or set a no-cache
-header for a file. Then browser will always serve the newest version.
Change your nginx config to reduce the expiration. You see that the difference between Expires
and Last-Modified
is 10 days, as reflected in the config file.
location ~* ^.+\.(jpg|jpeg|svg|gif|png)$ {
expires 1M;
try_files $uri @app;
}
来源:https://stackoverflow.com/questions/50814201/nginx-does-not-refresh-file-after-repeated-changing-old-last-modified-header-is