In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how Nginx enables proxy_cache caching, which has a certain reference value. Interested friends can refer to it. I hope you can learn a lot after reading this article.
Proxy_cache writes different configurations in the http segment and the server segment (location segment) of the Nginx configuration. The configuration in the http section is used to define the proxy_cache space, and the configuration in the server section is used to invoke the definition in the http section to enable caching of the server.
Http segment
Take the configuration of this site as an example:
Proxy_cache_path / home/nginx/proxy_cache/cache levels=1:2 keys_zone=proxycache:60m max_size=120m inactive=2h use_temp_path=on;proxy_temp_path / home/nginx/proxy_cache/temp;proxy_cache_key $host$request_uri
Where:
Proxy_cache_path
/ home/nginx/proxy_cache/cache: defines the root path of the proxy_cache generation file
Levels: by default, all cache files are placed in the root path specified above, which may affect cache performance. It is recommended to specify a level 2 directory to store cache files
Key_zone: the value of this is a string and can be written at will. It is used to define a storage area in shared memory to hold the cached key and metadata (similar to the number of uses), so that nginx can quickly determine whether a request hits the cache. 1m can store 8000 key
Max_size: maximum cache space. If not specified, all disk space will be used. When the disk limit is reached, the least used cache will be deleted.
Inactive: the expiration check period of the cache in memory. If the sample configuration is not accessed within 2 hours, the cache will be cleared regardless of whether the status is expired or not. It should be noted that the meanings of inactive and expired configuration items are different. Expired only determines the expiration time and does not delete the cache, while inactive deletes the expired cache directly.
Use_temp_path: if off, nginx writes the cache file directly to the specified cache file instead of using the temporary storage path specified by temp_path
Proxy_temp_path
/ home/nginx/proxy_cache/temp: defines the root path where proxy_cache generates temporary files. This item does not need to be filled in in use_temp_path=off
Proxy_cache_key
$host$request_uri: defines the name of the proxy_cache generation file. Values can be variables and strings supported by Nginx
Server segment
Also take the configuration of this site as an example:
Proxy_cache proxycache;proxy_cache_valid 304 2h delegation cacheology valid 403 444 24h delegation cacheology valid 404 2h delegation cacheology valid 500 502 2h delegation invalid_header http_403 http_404 http_500 http_502;proxy_cache_lock on;proxy_cache_lock_timeout 5s proxyroomnocache $proxynocache_atomxml $proxynocache_sitemapxml
Proxy_cache: the key_zone corresponding to the http segment is the name of the space used by the proxy_cache you defined. The name I used in the above example is "proxycache"
Proxy_cache_valid: caches the specified HTTP state and specifies the cache time. You can customize to write multiple configuration items
Proxy_cache_stale: this can greatly reduce the number of origin-pull. Therefore, the inactive can be extended appropriately.
Proxy_cache_lock: also reduce the number of origin-pull operations. The difference between the above and the above is whether the cache exists.
Proxy_no_cache: the value is a number of variables ($string). The value of this variable has only two types, 0 and non-0. As long as one of these variables has a value other than 0, the cache will not be triggered.
A little of my experience
Will generate something like "0 1 2 3 4 5 6 7 8 9 a b c d e f..." under the cache path you specified. Folders (when levels=2) that store cache files written to the hard disk
The status code of proxy_cache_valid cache needs to be defined according to your needs. Don't write 200 into it.
Inactive time and valid time need to be paid special attention. If the frequency of origin server updates is not low, you need to reduce these values according to your needs.
The $string used in proxy_no_cache is defined by something like "set $string 1;"
At present, I don't quite understand the usage of proxy_cache_use_stale and proxy_cache_lock, so the explanation is not very clear. I beg your pardon. It doesn't hurt if these two configurations are generally not used.
Thank you for reading this article carefully. I hope the article "how to enable proxy_cache caching in Nginx" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.