Nginx/tengine (after the name only nginx) only to do the cache performance than ATS, especially in the disk processing, but on the comprehensive ability Nginx is Danale, he set Web server, load balancing, cache three kinds of capabilities in one, Can be said to be a very comprehensive player. For example, a medium-sized site selection of the scene, the front is the load, the back end of a bunch of Apache server, now to the front-end load selection, although LVs and ha simply from the load performance than nginx better, but I will choose Nginx, because nginx in the load at the same time, The static content of the hotspot can be cache again, do an acceleration, the intangible between the back-end Web server to alleviate some of the pressure, improve the user experience, with stone. Nginx cache configuration is very flexible, there are all kinds of cache instructions, at first touch will not touch the north, I used a period of time, and now summarize the Nginx cache when I think of the three main sticking point--not to save, how long, use not?
Nginx Resource cache is determined by the client, the source and Nginx cache configuration, Nginx, if there is no cache policy configuration, the default according to request header, header response header information go to the standard HTTP cache judging mechanism (see Cache-control, Expires, cookies, these attributes), resources are cached only if a resource is not set to a blacklist that cannot be cached, and has a lifetime of more than 0 of the storage time, for the nginx cache judging process I spent my energy drawing a chart to share as follows:
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/FF/wKioL1cPbISQd-9iAAE4m5H2iTY852.png "title=" Qq20160414172412.png "alt=" Wkiol1cpbisqd-9iaae4m5h2ity852.png "/>
Test example, default configuration, a 200ok resource (http://www.haixiano.com/member/login.php) only cookie information is not max-age.
Test configuration parameters for the first time:
Proxy_cache_valid 10m;
#proxy_ignore_headers Set-cookie; Comment out
The header information and tests are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7E/FF/wKioL1cPbnayRC0JAAAsHoXTdhw133.png "title=" QQ picture 20160414181437.png "alt=" Wkiol1cpbnayrc0jaaashoxtdhw133.png "/>
The multiple access operations are as follows:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7F/02/wKiom1cPbm7TYRB_AABpzo-8Hb0722.png "title=" Qq20160414181754-02.png "alt=" Wkiom1cpbm7tyrb_aabpzo-8hb0722.png "/>
The multiple access logs are as follows ( all Miss):
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/03/wKiom1cPdxzTAO0OAACtDhgeoWQ438.png "title=" Qq20160414185240-11.png "alt=" Wkiom1cpdxztao0oaactdhgeowq438.png "/>
Summary: Although there is a 200ok information set cache time for 10 minutes, but the first decision of the cookie information is not saved, so do not see your 200ok resources cache time, the final conclusion is not saved.
Test configuration parameters for the second time:
#proxy_cache_valid 10m; Comment out
Proxy_ignore_headers Set-cookie;
The multiple access logs are as follows ( all Miss):
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/00/wKioL1cPd-jgaDnrAAD8HZBtfGw201.png "title=" Qq20160414185353-12.png "alt=" Wkiol1cpd-jgadnraad8hzbtfgw201.png "/>
Summary: Although the cookie information is ignored to tell you that the information can be stored in the cookie, but for the 200ok information set cache time is 0, so the final resources can not be saved.
Test configuration parameters for the third time:
Proxy_cache_valid 10m;
Proxy_ignore_headers Set-cookie;
The multiple access logs are as follows (after 1 accesses to miss, thenhit):
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/03/wKiom1cPeL7A0f8QAAC6thsutOU785.png "title=" Qq20160414185447-13.png "alt=" Wkiom1cpel7a0f8qaac6thsutou785.png "/>
Summary: First ignore the cookie information judgment, tell Nginx said cookie information is can be saved, after query no expires and max-age to find the default cache time, found that the default cache time for 200ok is 10m, so the final decision can be cached, The valid cache time is 10 minutes.
In conclusion, a resource can be cached only if it has both a cache and a life cycle with a cache time greater than 0, and then the next judgment will be taken after it is saved. So nginx for the resource whether the cache to go through two steps to determine, the first step to save, how long the second step, whether to use the cached resources for users to service also have to carry out the next layer of the use of the judgment, the detailed walk of the judging parameters can see I draw that picture, learning endless, continue to refuel.
This article is from the "Running Linux" blog, so be sure to keep this source http://benpaozhe.blog.51cto.com/10239098/1763897
Nginx/tengine cache caching mechanism-no storage, how long, using no methodology (picture self-drawing)