Caching in NGINX App Server
Caching in NGINX involves storing data in front of web servers. For instance, files automatically requested by a user when viewing a webpage can be saved in the NGINX cache directory. When the user revisits a page they’ve recently viewed, the browser can retrieve those files from the NGINX cache directory instead of the original server, which saves both time and bandwidth.
Caching enhances resource access performance in two main ways:
Step 1. It reduces the access time to the resource by storing it closer to the user.
Step 2. It speeds up resource generation by minimizing the number of accesses. For example, instead of rebuilding your blog’s homepage with every request, you can store it in a cache.
How to configure a cache on a NginxPHP server is covered in this post.
Using a NginxPHP server, you can leverage caching to improve performance by serving pre-compiled HTML responses for repeated PHP queries directly from the cache.
To set up caching, follow these steps:
Step 1. Sign in to your platform dashboard.
Step 2. Select the New Environment option.
Step 3. Set up the environment using NGINX as the application server. Define the cloudlet limits, enter a name for your environment, and then click the Create button.
Your environment will be set up shortly and will then appear in the list of available environments.
Step 4. To configure the cache, click the Config button for the NGINX node in your environment, then go to the etc directory and open the php.ini file.
Step 5. To enable caching on your NginxPHP server, you can use either APC or eAccelerator.
- eAccelerator
To enable APC, you need to remove the comment in the eAccelerator section.
Next, you’ll need to choose the directory to use for the disk cache. To do this, add the following line as shown in the picture below:
eaccelerator.cache_dir = /var/lib/nginx/cache
You can find all the extra settings right here. (https://github.com/eaccelerator/eaccelerator/wiki/Settings).
APC
To enable the APC accelerator, simply find the Accelerators section and remove the comment marks.
To explore more APC functions, click the link (https://www.php.net/manual/en/book.apcu.php) provided.
And that’s it! You are now prepared to utilize your PHP apps with NGINX caching.




