Caching in NGINX Balancer

Caching in NGINX Balancer

NGINX caching stores frequently requested data in front of the web servers. This reduces access time and decreases repeated requests to the application layer, improving performance and lowering backend-server load.

Caching Benefits

  • Reduces access time by storing requested resources closer to the user.
  • Improves resource-building speed by reducing repeated backend requests.
  • Reduces load on application servers by serving suitable content from the NGINX cache.

Create the Environment

  1. Log in to the platform dashboard.
  2. Click Create Environment.
Create environment
Create a new environment from the dashboard.
  1. Create an environment with several application servers and NGINX as the load balancer.
  2. Set the required cloudlet limits, specify the environment name, and click Create.
Environment wizard
Configure multiple application servers with NGINX as the balancer.

Enable NGINX Cache

  1. Click Config for the NGINX node.
  2. Navigate to conf.d > cache.conf.
NGINX balancer config
Open the NGINX configuration manager and navigate to cache.conf.

Uncomment the cache directives in cache.conf as shown in the source configuration.

NGINX cache.conf
Uncomment the required NGINX cache directives in cache.conf.

Cache Directives

proxy_cache_pathSets the cache path and cache parameters.
levelsDefines the hierarchy levels of the cache directory.
keys_zoneDefines the cache-zone name and RAM size, for example jelastic:32m.
proxy_cacheDefines the shared memory zone used for caching. Use off to disable caching inherited from a previous configuration level.
proxy_temp_pathDefines the directory used to store temporary data received from proxied servers. Up to three subdirectory levels can be configured.
proxy_cache_validSpecifies how long NGINX keeps cached content, for example 720m.

The source examples use the following directive patterns:

proxy_cache_path /var/lib/nginx/cache [levels=levels] keys_zone=name:size;

proxy_cache zone | off;

proxy_temp_path /var/lib/nginx/tmp [level1 [level2 [level3]]];

proxy_cache_valid {number}m;

Clear the Cache

If the cache needs to be cleared, set the proxy_cache_valid value to 0m.

proxy_cache_valid 0m;

After updating the cache configuration, save the changes and restart the NGINX node.

Restart NGINX node
Restart the NGINX balancer after saving the cache configuration.

Expected Result

NGINX stores eligible proxied content in its cache and serves repeated requests from the cached data when applicable, reducing application-server workload and improving resource-access performance.

Important Notes

  • Configure NGINX caching in conf.d > cache.conf.
  • proxy_cache_path defines the cache directory and shared-memory zone.
  • proxy_cache selects the shared cache zone or disables inherited caching.
  • proxy_temp_path defines temporary storage for proxied data.
  • proxy_cache_valid controls cache lifetime.
  • Set proxy_cache_valid to 0m when the cache needs to be cleared.
  • Restart the NGINX node after saving the changes.