$request_completion
The variable $request_completion returns the status of the request processing, indicating whether the request was completed successfully or not. — NGINX Core (HTTP)
Description
The $request_completion variable is utilized in NGINX to provide insight into the state of request processing. This variable is mainly set during the request lifecycle by the NGINX core, where it can take one of three values: 'ok', 'timeout', or 'failed'. It is particularly useful for logging and for conditional logic in NGINX configurations, enabling administrators to react differently based on whether a request was successfully completed, timed out, or failed for another reason. The variable is typically evaluated during the processing of a request after any response is generated or when a request error is encountered. If the server successfully finishes handling the request, the variable value is set to 'ok'. In cases where the request exceeds the timeout settings, it returns 'timeout', and if it fails due to other reasons, it returns 'failed'. This granularity in status reporting helps in diagnostics and performance monitoring of the NGINX server.
Config Example
log_format custom_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_completion'; access_log /var/log/nginx/access.log custom_format;
Subsystem
httpCacheable
YesContexts
http, server, location, ifEnsure that you are not using this variable in the wrong context, such as within an 'if' block, which can lead to unexpected behavior.
The variable may not be defined or accurate if accessed before the request processing is fully completed.