Caching in NGINX Balancer
With NGINX, caching entails data storage directly on the web server. For example, the files a user accesses while viewing a web page may be stored in your NGINX cache folder. The user’s browser can obtain those files from the NGINX cache rather than having to fetch them from the main server if they return to that page later. In addition to saving time, this lowers network traffic.
There are two basic ways that caching enhances performance when accessing resources:
- By keeping a copy of the resource closer to the user, it shortens the time it takes to access it.
- By reducing the quantity of requests, it expedites the generation of resources. For example, you can cache your blog’s homepage so that it doesn’t have to be recreated each time a visitor comes by.
How to configure caching on an NGINX load balancer platform is covered in this guide.
You can use caching with NGINX load balancer to reduce the workload on application servers. To apply caching, take the following actions:
Step 1. Log in to the dashboard of the platform.
Step 2. Select “Create Environment” from the menu.
Step 3. Install many application servers and use NGINX as a load balancer to set up the environment. To finish the configuration, specify the cloudlet limitations, give the environment a name, and click the Create button.
Within a minute, your environment will be created and will show up in the list of environments.
Step 4. To configure the cache, click on the “Config” button for the NGINX node in your environment, then navigate to conf.d > cache.conf.
Step 5. To enable caching, remove the comment marks (typically represented by #) from the lines of code, as illustrated in the image below.
- The path and settings for caching in NGINX are configured using the `proxy_cache_path` directive. Below is an explanation of its specifications:
- Path: Indicates the path (such as/var/lib/nginx/cache}) where cached data will be kept.
- Levels: Specifies how many directory tiers (for example, {[levels=levels]}) to employ in the caching hierarchy.
- Keys Area: gives the cache zone a special name and a designated RAM size (e.g., name:size}, such as jelastic:32m}). This makes it possible for NGINX to effectively handle and store cached material.
- The proxy_cache directive is used to create a shared memory storage area (called a “zone”) for caching in NGINX. This zone can be referenced and used in multiple configurations throughout NGINX. The `off` parameter, when specified, disables caching that may have been enabled in a previous configuration level.
- A directory (/var/lib/nginx/tmp}) where NGINX keeps temporary files containing data received from proxied servers is specified by the proxy_temp_path} directive. Under the designated directory, you can arrange these temporary files into a hierarchical subdirectory structure with up to three levels (level1}, level2}, and level3}). This facilitates effective temporary file management and organization within NGINX.
- The proxy_cache_valid {number}m directive specifies how long NGINX should keep cached content before considering it stale. For example, 720m means NGINX will keep cached content valid for 720 minutes (or 12 hours) before refreshing it from the origin server.
To learn more about additional directives, please click on the provided link for more information.
Step 6. Save the changes you made and then restart the node to apply the modifications.





