1. 程式人生 > 實用技巧 >Nginx基於ldap的認證

Nginx基於ldap的認證

1,基於全員的認證

NGINX基於ldap的認證,一旦出手,誰與爭鋒,日常業務當中,有太多頁面內容,通過NGINX代理,有時需要新增認證以提高安全,使用NGINX的密碼策略,又極不方便,容易出現一個賬號多人使用的情況,而今接入到ldap,所有許可權迴歸到ldap中,簡直不要太優雅。

NGINX基於ldap的認證需要nginx-auth-ldap模組兒,可以在原有已經在用的NGINX中,新增進去,或者直接全新的NGINX進行配置。

cd /opt
git clone https://github.com/nginxinc/nginx-ldap-auth

然後編譯安裝NGINX:

tar xf nginx-1.16
.0.tar.gz yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel libxslt-devel ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --add-module=/opt/nginx-auth-ldap make && make install

然後進入正式配置:

cat /usr/local/nginx/conf.d/test.conf 

        ldap_server openldap {

        url ldap://10.0.20.19:389/dc=aihelp,dc=net?uid?sub?(&(objectClass=organizationalPerson));

        binddn "cn=admin,dc=aihelp,dc=net";

        binddn_passwd "123456";

        #require valid_user;            #ldap 所有使用者都可以登入訪問

#下面3行是基於特定組的認證 group_attribute uniquemember; group_attribute_is_dn on; require group
"cn=jenkins,ou=group,dc=aihelp,dc=net"; } server { listen 8002; server_name localhost; location /hello { default_type text/plain; auth_ldap "Restricted Space"; auth_ldap_servers openldap; echo hello; } location ~ /hi { default_type text/plain; echo hi; } }