Nginx uses Proxy_cache to cache files

Source: Internet
Author: User
Tags browser cache


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.