Does nginx support ldap authentication? I have just migrated from apache and would like to move all of my authentications which are based on openldap and mod_auth_ldap to nginx. Let me know if that is possible.
From this page listing all the modules nginx has, i don't see any mention about LDAP. Thanks,
nginx doesn't do LDAP: you have to use
xsendfile
with a 3rd party script you create to handle LDAP authenticationhttp://wiki.nginx.org/NginxXSendfile
There is an unofficial LDAP module for nginx : nginx-auth-ldap.
There is a 3rd party module
nginx-auth-ldap
that you can use. I have not tried it yet, but I may update my answer later.using nginx X-accel
The documentation for
X-accel
just explains that a page may use a header to have nginx serve a file (rather thanPHP
ordjango
orruby
or name-your-not-as-efficient-as-nginx-stack-here).e.g. workflow:
/download.php?path=/data/file1.txt
,download.php
returnsWWW-Authenticate
+401 Unauthorized
,/download.php?path=/data/file1.txt
but nownginx
has the credentials,nginx
may pass$remote_user
and$http_authorization
tofastcgi
script,download.php
does the authentication and decides whether to return403 Forbidden
or set the headerX-Accel-Redirect
header.setting nginx
internal
locationWhile you can use
X-Accel
to serve static assets, the use case here is we want the requests to be authenticated, which is why we useinternal
.setting up the download script
Here we go:
please note: the PHP script uses
PHP_AUTH_USER
andPHP_AUTH_PW
, which is captured bynginx
, so in order to use them in the PHP script, we need to give to provide them explicitly.cooking up an ldap authentication in PHP
For my use case, I installed
php-fpm
andphp-ldap
on my system.Here is a decent authenticate function:
Here is a decent code path for forbidden access:
And for the meat of the LDAP authentication:
Here you have the main body of the script which uses the request uri.
semi-transparent file browsing
I also published this as a gist:
and pretty much the same PHP script except the body:
In short: Yes, NGINX supports LDAP. There are two add-on modules available: NGINX has one, and there is another one available on github. The NGINX solution seemed rather complex at first glance, so I went with the latter choice, which is called nginx-auth-ldap. I put up some installation notes regarding my experience in the following thread:
Add ldap authentication to nginx on RHEL 7
Looks like somebody got answer to your question on http://forum.nginx.org/read.php?2,18552