auth_digest_user_file

Specifies the user file for digest authentication in NGINX.

Syntaxauth_digest_user_file file_path;
Defaultnone
Contexthttp, server, location, limit_except
Arguments1

Description

The auth_digest_user_file directive is used to specify the path to the user file that contains the username and hashed passwords for digest authentication. This file must contain user credentials in a specific format that NGINX can parse to authenticate users. Each line in the file typically contains the username, realm, and hashed password, allowing NGINX to verify user credentials against the requests coming in from clients. When NGINX receives a request requiring authentication, it will check the provided credentials against those stored in this user file.

This directive can be used in several contexts, including http, server, location, and limit_except, providing flexible authentication options at different levels of the configuration hierarchy. The user file must be defined within the relevant context and will apply to the corresponding requests handled by NGINX. If multiple directives are defined at different hierarchy levels, the behavior will depend on the closest context match, with location blocks overriding server and server overriding the http level definitions.

To set this directive, an argument should point to the absolute path of the user file. It is crucial to ensure that the user file is secure, as it contains sensitive information, and appropriate file permissions should be set to prevent unauthorized access.

Config Example

http {
    auth_digest_user_file /etc/nginx/.htdigest;
    location /protected {
        auth_digest "Protected Area";
        # Additional configuration...
    }
}

Ensure the user file is in the correct format for digest authentication, or NGINX will not successfully authenticate users.

Pay attention to file permissions; the user NGINX runs under must have read access to the user file.

If multiple contexts specify user files, the closest match in the configuration will take precedence, which may not be what you expect.

← Back to all directives