degrade

The 'degrade' directive is used to control the fallback mechanism when a primary server is unavailable.

Syntaxdegrade;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The 'degrade' directive in NGINX allows administrators to specify how the server should behave when a primary backend server is not available. This directive is particularly useful for load balancing setups where there might be multiple upstream servers or services. By enabling the degrade directive, NGINX will allow server requests to be routed to a designated secondary server or a predefined set of servers even when one or more upstream servers are down. This can help maintain service availability and ensure that users continue to receive responses even in the case of failures.

When the degrade directive is enabled, it effectively changes the failure behavior by permitting requests to be served from secondary resources instead of outright denying them. This is particularly beneficial in high-availability environments where maintaining service continuity is critical. Administrators must ensure that the appropriate fallback configurations are in place, such as defining backup servers in the upstream context, to leverage this directive effectively. Moreover, the success of using this directive relies on the overall health checks and proper configuration of upstream servers.

Config Example

http {
    upstream backend {
        server primary_server;
        server backup_server backup;
    }
    server {
        location / {
            proxy_pass http://backend;
            degrade;
        }
    }
}

Ensure that upstream servers are properly defined; missing configurations can lead to unexpected behaviors.

The degrade directive only applies when using upstreams; it may not have an effect in simple server contexts.

← Back to all directives