$uid_set

The $uid_set variable contains the user ID set for the current request context in NGINX. — NGINX Core (HTTP)

$uid_set NGINX Core (HTTP)

Description

The $uid_set variable is defined within the NGINX Core and is utilized to reflect the user ID that has been set for the current request. This variable is particularly relevant when handling specific access controls and security configurations based on user identity. The user ID is typically established through authentication mechanisms where a user successfully logs in or makes a request that includes identification credentials. When $uid_set is used, it is often manipulated internally by various modules that derive user credentials from headers or session tokens. The value of this variable can change mid-transaction if the request undergoes a redirection or if the back-end application modifies the authentication context. The typical values for $uid_set might range from a numerical representation of the user ID to an empty string when there's no authenticated user found.

Config Example

server {
    listen       80;
    server_name  example.com;

    location / {
        if ($uid_set) {
            return 200 'User ID is set';
        }
        return 403 'Access denied';
    }
}

Subsystem

http

Cacheable

Yes

Contexts

http, server, location, if

Ensure that authentication modules are properly configured to set the user ID; otherwise, $uid_set may remain empty.

Using $uid_set in the wrong context (e.g., outside request processing) may lead to unexpected results or errors.