open_file_cache_errors

The 'open_file_cache_errors' directive controls whether to cache error statuses when opening files in NGINX.

Syntaxopen_file_cache_errors on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The 'open_file_cache_errors' directive is a performance optimization feature in NGINX that determines whether the server should cache error responses when it attempts to access files. When enabled, NGINX will cache the error statuses associated with file access attempts, which can improve response times for repeated requests for the same files that may not exist or are unreadable. This prevents NGINX from having to check the file system each time a file is requested, thus reducing disk I/O and improving performance under high load conditions.

The directive accepts a flag as its argument: "on" to enable caching of these errors and "off" to disable it. By default, this directive is turned off, meaning error statuses are not cached, and every file access request will check the file system anew, which may lead to higher latency especially if multiple requests are intended for the same missing or inaccessible files. In scenarios where reliability of error status is critical (such as in dynamically generated content), use with caution as it can serve stale errors if not configured properly.

Config Example

http {
    open_file_cache_errors on;
}

server {
    location / {
        open_file_cache_errors on;
    }
}

Caching errors might lead to stale responses if a file's status changes and the cache isn't refreshed.

If enabled, long-running error responses may result in unnecessary disk I/O if the errors are not cached properly.

← Back to all directives