tengine(nginx)開啟openldap用戶認證

1、安裝依賴。

<code>#yum -y install openldap-devel
#yum install pcre pcre-devel -y
#yum -y install openssl openssl-devel
#yum groupinstall "Development Tools" -y/<code>

2、下載nginx-auth-ldap模塊。

<code>#yum -y install git
#cd /soft/
#git clone https://github.com/kvspb/nginx-auth-ldap.git/<code>

3、下載/安裝tengine壓縮包。

<code>#cd /soft
#wget http://tengine.taobao.org/download/tengine-2.2.2.tar.gz
#tar zxvf tengine-2.2.2.tar.gz
# cd tengine-2.2.2
#./configure --prefix=/soft/tengine --with-threads --with-http_ssl_module --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_addition_module --with-http_v2_module
#make && make install/<code>

4、引入nginx ldap模塊。

<code>#cd /soft/tengine/sbin
#./dso_tool --add-module=/soft/nginx-auth-ldap/<code>

5、nginx引入ldap模塊及其相關配置

<code>#grep -Ev '^#|    #|^$'  /soft/tengine/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
dso {
load ngx_http_auth_ldap_module.so;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8023;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
ldap_server wanyan-ldap {
\turl ldap://1.2.3.4:389/DC=wanyan,DC=cn?cn?sub?(objectClass=inetorgperson);
\tbinddn "cn=admin,dc=wanyan,dc=cn";
\tbinddn_passwd "wanyanxxx";
\tgroup_attribute uniqueMember;
\tgroup_attribute_is_dn on;
\trequire valid_user;
}
server {
listen 8085;
server_name localhost;
location /status {
stub_status on;
auth_ldap "Forbidden";
auth_ldap_servers wanyan-ldap;
}
}
}/<code>

最後驗證的部分

訪問 http://xx.xx.xx.xx:8085/status 輸入ldap的賬號和密碼即可以登陸

<code>Active connections: 2 
server accepts handled requests request_time
2 2 4 0
Reading: 0 Writing: 1 Waiting: 1 /<code>

最後附加openldap搭建方式

<code>首先生成openldap服務
#docker run -p 389:389 --name myopenldap --network bridge --hostname openldap-host --env LDAP_ORGANISATION="wanyan" --env LDAP_DOMAIN="wanyan.cn" --env LDAP_ADMIN_PASSWORD="xxxx" --detach osixia/openldap
phpldapadmin服務
#docker run -d --privileged -p 10004:80 --name myphpldapadmin --env PHPLDAPADMIN_HTTPS=false --env PHPLDAPADMIN_LDAP_HOSTS=172.17.0.6 --detach osixia/phpldapadmin/<code>
tengine(nginx)開啟openldap用戶認證

<code>


分享到:


相關文章: