$document_uri

The $document_uri variable contains the URI of the request without any query string and with decoded percent-encoded characters. — NGINX Core (HTTP)

$document_uri NGINX Core (HTTP)

Description

The $document_uri variable is set during the processing of a request in NGINX, representing the part of the URI that is used to identify the requested resource. Unlike the $request_uri variable which includes the query string, $document_uri strictly contains the URI path, making it suitable for scenarios where the query string is not needed. This variable is particularly useful when documenting or logging the URIs being accessed on the server, enabling the tracking of intended resource requests without interference from any URL query parameters. The value of $document_uri is determined after the request has been processed by the NGINX routing system, specifically within the location context. This means that it can reflect decisions made by NGINX regarding URI rewriting or the use of specific location blocks. Typical values for $document_uri can range from simple paths like "/index.html" to structured URIs like "/products/item123". Any percent-encoded characters in the URI are decoded to ensure cleaner and more human-readable output when using this variable. Usage of this variable within access logs, rewrites, or conditional statements can simplify configuration, especially when specific actions are needed based on the resource that is being accessed. For example, log formats can include $document_uri to trace which documents are frequently requested.

Config Example

log_format mylog '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$document_uri"';

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

Subsystem

http

Cacheable

No

Contexts

http, server, location, if

Remember that $document_uri does not include the query string; use $request_uri if the query string is needed.

The variable is set after the request is mapped to a location; ensure that you are in a valid context where it is defined.