auth_pam

The auth_pam directive configures PAM (Pluggable Authentication Module) authentication for specified HTTP contexts in NGINX.

Syntaxauth_pam "realm";
Defaultnone
Contexthttp, server, location, limit_except
Arguments1

Description

The auth_pam directive is part of the PAM authentication dynamic module for NGINX, which allows administrators to implement authentication mechanisms using PAM to secure areas of an NGINX-served website. By setting this directive within an http, server, location, or limit_except context, the specified authentication realm is presented to users when they attempt to access protected resources. It works in conjunction with the auth_pam_service_name directive, which specifies the PAM service that should be leveraged for authentication processes.

When a user accesses a protected resource, NGINX queries the PAM system for user credentials based on the service name defined by auth_pam_service_name, which defaults to "nginx" if not explicitly set. This mechanism requires proper configuration of PAM to connect to the desired authentication backend, such as a Unix password database or an external LDAP service. The auth_pam_set_pam_env directive may also be utilized to set PAM-related environment variables for the authentication session, enhancing the flexibility of the authentication scenario in dynamic web applications.

One important consideration when using auth_pam is that the user running the NGINX service must have appropriate permissions to access necessary files—like /etc/shadow—if using standard Unix authentication methods. This may be a security concern and requires careful consideration of user permissions and file access restrictions.

Config Example

location /secure {
    auth_pam              "Secure Zone";
    auth_pam_service_name "nginx";
}

Ensure the web server user has appropriate access permissions for files required by PAM.

If authentication fails, users may receive confusing error messages, so consider implementing user-friendly error handling.

Avoid exposing sensitive areas without proper access controls, especially in production environments.

← Back to all directives