Caching in NGINX App Server

Caching in NGINX is the process of storing data in front of web servers. For example, the files a user automatically requests by looking at a web-page can be stored in your NGINX cache directory. When a user returns to a page he’s recently looked at, the browser can get those files from the NGINX cache directory rather than the original server, saving time and traffic.

So caching improves performance while accessing to a resource in two ways:

  • reduces the access time to the resource by copying it closer to the user.
  • increases the resource building speed by reducing the number of accesses. For example, instead of building the homepage of your blog at each request, you can store it in a cache.
    This instruction shows how to set up a caсhe on the NginxPHP server in the Jelastic cloud.
    With NginxPHP server you can use the caching for improving performance through getting from the cache already compiled html replies for repeated php queries.

Note: We limit the size of the disk cache to 5 GB.

To perform caching follow the instruction:

  • Log into the

    Jelastic Manager

  • Ask Jelastic to create the environment. caching nginx server Снимок

  • Create the environment with the NGINX as an application server, specify the cloudlet limits, type the name of the environment and click Create button. caching nginx server 3 In a minute your environment will be created and appears in the environment list.

  • For setting up the cache click Config button for NGINX node in your environment and navigate to etc > php.ini. caching nginx server 4

  • For enabling cache on your NginxPHP server you can use APC or eAccelerator.

    • eAccelerator
      For using eAccelerator (can be used only with the PHP 5.3 and 5.4 versions) you should uncomment it in the Accelerators section: caching nginx server 4 Now you need to specify the directory which will be used for the disk cache. For that add the following line as it is shown in the picture above: eaccelerator.cache_dir = "/var/lib/nginx/cache” caching nginx server 5 All additional settings you can find here.
    • APC
      To use APC accelerator (can be used only with the PHP 5.3 and 5.4 versions) you should just uncomment it in the Accelerators section: caching nginx server 6 To find out what additional APC functions are available follow the link.

That’s all! Now you can use NGINX caching for your PHP applications.

What’s next?