auth_ldap

auth_ldap 指令用于针对指定的 LDAP 服务器启用基于 LDAP 的身份验证。

语法auth_ldap "realm_name";
默认值none
上下文http, server, location, limit_except
参数1

说明

auth_ldap 指令是 NGINX 的 LDAP Authentication 模块的一部分,该模块允许管理员根据 LDAP 服务器的条目实现身份验证。该模块使用为 LDAP 服务器指定的参数(例如 urlbinddnbinddn_passwd)来对 LDAP 目录中的用户进行身份验证。该指令可以放在不同的上下文级别——即 httpserverlocationlimit_except——从而根据指令在配置中的作用域灵活定义认证条件。

配置示例

http {
    ldap_server my_ldap {
        url ldap://ldap.example.com:389/ou=users,dc=example,dc=com?uid?sub?(objectClass=person);
        binddn "cn=admin,dc=example,dc=com";
        binddn_passwd "password";
        group_attribute memberOf;
        group_attribute_is_dn on;
        require valid_user;
    }

    server {
        listen 80;
        server_name example.com;

        auth_ldap "Restricted Area";
        auth_ldap_servers my_ldap;

        location / {
            proxy_pass http://backend;
        }
    }
}

确保 LDAP 服务器的 URL 已使用适当的 LDAP 协议(ldap:// 或 ldaps://)正确指定。

bind DN 和密码必须正确设置,以允许绑定到 LDAP 服务器。

组属性配置错误可能导致认证失败;请确保 group_attribute 已正确配置并在 LDAP 中存在。

← 返回所有指令