nginx.conf part of the content:
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;
#设置缓存的key
proxy_cache_key $host $uri$is_args$args;
#设置状态码为200和304的响应可以进行缓存, and the cache time is 1 days
proxy_cache_valid 304 1d;
Expires 30d;
}
Nginx does not cache reason
By default, whether the cache is nginx by the Nginx cache server is determined by the source server, and the caching server needs to strictly follow the header of the source server response to determine whether caching and caching is frequent.
Headers are mainly as follows:
Cache-control:no-cache、no-store
If these two values are present, the Nginx cache server is definitely not cached
Expires:1980-01-01
If the date appears earlier than the current time, it is not cached.
Resolving non-caching scenarios
2.1 Method One:
To modify the header of a program or source server Web program response
2.2 Method Two:
The Nginx agent directly adds the following sentence:
Proxy_ignore_headers x-accel-expires Expires Cache-control Set-cookie;
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.