![NGINX plus Directives and their roles in configuring basic Caching 1 Automation and Cloud](https://ashnik-images.s3.amazonaws.com/prod/wp-content/uploads/2021/01/20045317/Automation-and-Cloud.jpg)
![NGINX plus Directives and their roles in configuring basic Caching 1 Automation and Cloud](https://ashnik-images.s3.amazonaws.com/prod/wp-content/uploads/2021/01/20045317/Automation-and-Cloud.jpg)
In today’s world connections are happening to the application or to the website from multiple sources-mobile devices, tablets, desktops, kiosks etc. This means availability, stability and responsiveness of the application or the website has become most important factor in business continuity. The way applications are written and the infrastructure on which they are deployed, plays a key role in delivering performance. Today we would talk about one of the most important aspect – caching and how it helps to improve the performance. Though it is a basic factor yet very often is ignored.
NGINX Plus is mostly deployed as web accelerator, reverse proxy/load balancer and also has a extensive caching features. Below section gives quick view on the directives which can help you configure basic caching with NGINX Plus.
** proxy_cache_path
Helps you set the path and configuration of the cache
** proxy_cache
Helps you activate caching
** proxy_cache_use_stale
Syntax : proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | off …;
Determines in which cases a stale cached response can be used when an error occurs during communication with the proxied server. It delivers the stale file instead of relaying the error to the client.
** proxy_cache_revalidate
instructs NGINX to use conditional GET requests when refreshing content from the origin servers. Enables revalidation of expired cache items using conditional requests with the “If-Modified-Since” and “If-None-Match” header fields.
proxy_cache_min_uses
Sets the number of requests after which the response will be cached
** proxy_cache_lock
if multiple clients request a file that is not current in the cache, only the first of those requests is allowed through to the origin server. The remaining requests wait for that request to be satisfied and then pull the file from the cache. Without proxy_cache_lock enabled, all requests that result in cache misses go straight to the origin server.
** NGINX can Ignore Cache-Contraol Headers with proxy_ignore_headers directive
For example, with this configuration:
location /images/ {
proxy_cache my_cache;
proxy_ignore_headers Cache-Control;
proxy_cache_valid any 30m;
…
}
NGINX ignores the Cache-Control header for everything under /images/.
** proxy_cache_valid directive enforces an expiration for the cached data and is required if ignoring Cache-Control headers. NGINX does not cache files that have no expiration.
** NGINX can Cache POST requested with the proxy_cache_methods Directive
e.g proxy_cache_methods GET AHEAD POST;
** NGINX can Cache Dynamic content provded Cache-Controls allows it. Even if for short period you are able to cache dynamic content it helps on reducing load on origin server and databases.
** Byte Range Requests
NGINX complies to byte range request and serves only the specified butes of the item to the client if the file in cache is up-to-date. If the file is not cached, NGINX sends that range to the client as it is encountered in download stream.
** NGINX supports selective purging of cached files. This can be of use when the file is update don origin server but still valid in the NGINX Plus cache i.e max-age is still valid. With the cache-purge feature of NGINX Plus, this file can be deleted ( proxy_cache_purge)
There are many more ways you can customize and tune NGINX caching. To learn even more about caching with NGINX, please take a look at the following resources:
- The ngx_http_proxy_module section of the of the NGINX documentation contains all of the configuration options for content caching.
- The NGINX Content Caching Webinar is available on demand. The webinar steps through much of the information presented in this blog post.
- The Content Caching section of the NGINX Plus Admin Guide has more configuration examples and information on tuning the NGINX cache.
- The Content Caching with NGINX Plus product page contains an overview on how to configure cache purging with NGINX Plus and provides other examples of cache customization.
As an Nginx partner we can help you in your business performance.
For any support or query reach us at success@ashnik.com.
Table of Contents