$status

The $status variable returns the HTTP response status code of the current request being processed by NGINX. — NGINX Core (HTTP)

$status NGINX Core (HTTP)

Description

The $status variable in NGINX represents the status code of the response generated by the server for the current request. It is set automatically by NGINX during the processing of the request, reflecting the outcome of the request handling. Common HTTP status codes include 200 for successful responses, 404 for not found errors, and 500 for server errors, among others. This variable becomes accessible once NGINX handles the request and generates a corresponding response. You can utilize this variable for various purposes, such as logging the status of requests or implementing conditional actions based on the outcome of the requests. For example, if a request results in a 404 status code, you might want to trigger specific error handling behavior or logging to track how often users encounter page not found errors.

Config Example

log_format custom '$remote_addr - $remote_user [$time_local] "${request}" $status ${body_bytes_sent} "$http_referer" "$http_user_agent"';

access_log /var/log/nginx/access.log custom;

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Ensure that the $status variable is accessed after the request has been processed. Accessing it too early in the configuration may yield unexpected results.

When using the $status variable in conditional expressions, be aware of NGINX's evaluation order to avoid incorrect assumptions based on its value.