$request
The $request variable contains the full request line received from the client, including the HTTP method, URI, and HTTP version. — NGINX Core (HTTP)
Description
The `$request` variable in NGINX is set during the processing of an HTTP request and captures the entire request line, which includes the HTTP method (GET, POST, etc.), the requested URI, and the HTTP protocol version (HTTP/1.1, HTTP/2, etc.). This variable is populated when NGINX begins to handle a request and is utilized in various contexts to provide detailed information about the request being processed. As such, its value typically looks like 'GET /index.html HTTP/1.1' or 'POST /api/v1/resource HTTP/2'. The `$request` variable can be particularly useful for logging purposes or for customizing responses based on specific HTTP methods or requested URIs. For example, by inspecting the contents of the `$request` variable, server rules can be designed to conditionally rewrite URLs, log access patterns, or even apply security policies based on the request method. It is worth noting that once a request has been processed and a response has been generated, the `$request` variable holds the state of the request as it was when initially received, unmodified by later processing steps or internal actions.
Config Example
http {
log_format custom_format '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent';
access_log /var/log/nginx/access.log custom_format;
}Subsystem
httpCacheable
YesContexts
http, server, location, ifEnsure proper context usage; it is primarily available in request-processing contexts such as location and server.
Using `$request` does not account for rewritten URIs unless specifically requested after an internal rewrite.