ScaleScaleScaleScale

Tips / Nginx


How to enable Nginx Open File Cache

open_file_cache is one of those little thing that can do magic if you use Nginx with high traffic websites. open_file_cache can help you to cache file metadata information, I repeat, metadata information, not the content of each file, those are two different things that you need to have in mind. If you have little traffic you may not see any performance difference, but if you serve a few hundred of mbits or a couple of GBits of traffic you may see a big change in your server performance.

How do I enable open_file_cache on Nginx?

Edit nginx.conf, mine is located at:

nano -w /etc/nginx/nginx.conf

Then add this to the httpd block configuration:

open_file_cache          max=10000 inactive=10m;
open_file_cache_valid    20m;
open_file_cache_min_uses 1;
open_file_cache_errors   on;

Apply the changes:

service nginx reload

Directives Explanation

open_file_cache max=1000: sets maximum number of entries in the cache.
Other options: inactive=10m; – specifies the time when the cached item is remove / Off – prohibits the cache activity.

open_file_cache_valid 20m; let nginx to check if the information it is holding is valid every 20 minutes.

open_file_cache_min_uses 1; this directive sets the minimum use number of a file within the time specified in the directive parameter inactive in open_file_cache.

open_file_cache_errors on; specifies whether or not to cache errors when searching for a file (example 404 file not found errors).

Popular search terms:

  • open gbits file
  • open cache file
  • nginx open file cache
  • how to open files in NGINX server
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Rodehoed

    Hi,

    Just hijacking your newest post to let you know: nice site! As a long time Apache admin I was “forced” to use NGINX for a customer too. Hardest part is to let go the .htaccess file 😀

    Greetz,
    Rodehoed

  • admin

    Glad you like it 🙂

    Regards.