Nginx can use Proxy_cache to cache files, you can query
Http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_path
Here's how:
1. Proxy_cache_path Specifies the cache path, which is added in http:
Proxy_cache_path/usr/local/ngin/proxy_cache levels=1:2 keys_zone=content:20m inactive=1d max_size=100m;
/*levels Setting the directory hierarchy
Keys_zone Setting the cache name and shared memory size
Inactive is deleted in 1 days if no one is visited within the specified time.
Max_size Maximum cache space */
2, in the location definition:
Proxy_cache content; Content corresponding to root Keys_zone
Proxy_cache_valid 304 301 302 10d; Which states are cached for how long
Proxy_cache_valid any 1d; How long does the other cache
Proxy_cache_key $host $uri$is_args$args; Hash by key, define the value of key
3, can use Add_header in location to specify the header information, convenient browser view:
Add_header X-via $server _addr;
Add_header X-cache $upstream _cache_status;
4, browser front-end use developer tools to view:
The first access, the status is Miss, no hit.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/70/3C/wKiom1W0lQaS6w97AAHQNZANrew364.jpg "style=" float: none; "title=" A.png "alt=" Wkiom1w0lqas6w97aahqnzanrew364.jpg "/>
Using CTRL+F5 (do not use local browser cache), the return status is hit, hits.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/70/3C/wKiom1W0lQbzYtI5AAHEkBcnp88223.jpg "style=" float: none; "title=" C.png "alt=" Wkiom1w0lqbzyti5aahekbcnp88223.jpg "/>
This article is from the "Autumn Fairy tale" blog, please be sure to keep this source http://wushank.blog.51cto.com/3489095/1678480
Nginx uses Proxy_cache to cache files