4

I know how to auth the users via LDAP in apache2:

# put the following in the VirtualHost

<VirtualHost *:443>
    ServerAdmin user1@bar.foo.com 
    DocumentRoot /var/www
    <Directory />
    AuthType Basic
    AuthName "Please provide USERNAME AND PASSWORD"
    AuthBasicProvider ldap
    Order allow,deny
    Allow from all
    AuthLDAPURL "ldaps://ehh.foo.com/ou=ehh,o=foo.com?mail"
    Require valid-user
    Require ldap-attribute emailAddress=someuser@bar.foo.com

Q: But we need to use nginx. How can we configure nginx to auth via LDAP?

Using Ubuntu 12.04.5

6

For this you need to download/clone, compile and install nginx-auth-ldap

You can download the zip file:

wget https://github.com/kvspb/nginx-auth-ldap/archive/master.zip
unzip master.zip

then cd to your nginx source folder and do:

./configure --add-module=~-/nginx-auth-ldap-master
sudo make install

After that you can configure nginx:

http {
  ldap_server test1 {
    url ldap://192.168.0.1:3268/DC=test,DC=local?sAMAccountName?sub?(objectClass=person);
    binddn "TEST\\LDAPUSER";
    binddn_passwd LDAPPASSWORD;
    group_attribute uniquemember;
    group_attribute_is_dn on;
    require valid_user;
  }

  ldap_server test2 {
    url ldap://192.168.0.2:3268/DC=test,DC=local?sAMAccountName?sub?(objectClass=person);
    binddn "TEST\\LDAPUSER";
    binddn_passwd LDAPPASSWORD;
    group_attribute uniquemember;
    group_attribute_is_dn on;
    require valid_user;
  }
}

server {
    listen       8000;
    server_name  localhost;

    auth_ldap "Forbidden";
    auth_ldap_servers test1;
    auth_ldap_servers test2;

    location / {
        root   html;
        index  index.html index.htm;
    }

}

As indicated in the modules documentation.

3

You can also use the auth_pam module. It has for example been included in the last two stable Debian releases. It supports LDAP authentication (and a lot more) through PAM.

  • There's a pam module for nginx authentication?! – Octavian May 15 at 23:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.