English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Content of nginx.conf section:
proxy_temp_path /nginx/cache/temp; proxy_cache_path /nginx/cache/path levels=1:2 keys_zone=cache_test:2048m inactive=7d max_size=10g; ...... location ~ .(gif|jpg|jgep|png)$ { proxy_pass http://upstreams; proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; proxy_cache cache_test; #Set the cache key #Set the cache key to $host$uri$is_args$args; #Set status code to200 and304of the response can be cached, and the cache time is1days proxy_cache_valid 200 304 1d; expires 30d; }
Reasons why nginx does not cache
By default, whether nginx caches is decided by the nginx caching server and the source server together. The caching server needs to strictly comply with the source server's response header to decide whether to cache and the duration of caching.
The main headers are as follows:
Cache-control: no-cache, no-store
If these two values appear, the nginx caching server will never cache.
Expires:1980-01-01
If the date is earlier than the current time, it will not be cached either.
Solution for non-caching plan
2.1 Method One:
Modify the program or the source server web program response header
2.2 Method Two:
nginx proxy directly add the following sentence:
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
Summary
That's all for this article. I hope the content of this article can bring you some help in learning or working. If you have any questions, you can leave a message for communication.