scgi_cache

The 'scgi_cache' directive enables caching of responses from SCGI servers in NGINX.

Syntaxscgi_cache path;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The scgi_cache directive is used within the context of an HTTP server or location block in NGINX, enabling the caching of SCGI (Simple Common Gateway Interface) responses. When this directive is set with a path to a cache zone, all responses from the upstream SCGI server are stored in that cache, allowing for reduced latency and lower load on the backend server for subsequent requests. The caching behavior is controlled further by additional parameters and directives such as scgi_cache_key, which determines how cached items are indexed, and scgi_cache_path, which specifies the cache storage location and configurations.

The directive works in conjunction with other SCGI-related configurations. For example, specifying scgi_pass will direct traffic to an upstream SCGI server, while scgi_cache_valid can dictate how long a response can be cached based on the HTTP status code. It's essential to effectively manage the cache size and expiration to prevent stale data or excessive memory usage. Caching can significantly improve performance but requires attention to detail to maintain effectively.

Config Example

http {
    scgi_cache /var/cache/scgi;
    server {
        location /app {
            scgi_pass backend;
            scgi_cache my_cache;
            scgi_cache_valid 200 1h;
        }
    }
}

Ensure that the cache path is writable by the NGINX worker processes.

Be aware of cache invalidation strategies; stale data may be served if not handled properly.

Do not confuse 'scgi_cache' with 'proxy_cache', as they cater to different protocols.

← Back to all directives