Nginx如何支持LDAP認證

  1. 安裝Centos7.0

    最小版安裝時,注意自行生成ifcfg-eth0,並設置DNS,主機名。

    幾個地址:

    /etc/sysconfig/network-scripts

    /etc/sysconfig/network

    /etc/resolv.conf

    Yum安裝net-tools,CentOS7默認沒有ifconfig。

    關閉防火牆,CentOS默認不是iptables是Firewall:

    systemctl stop firewalld.service #停止firewall

    systemctl disable firewalld.service #禁止firewall開機啓動

  2. 安裝Nginx,使用淘寶(http://tengine.taobao.org/)的tengine

    安裝方法參考我之前的博客http://noc.lzit.edu.cn/wordpress/?p=1392或者https://blog.51cto.com/lovemjd/2564280

  3. 與之前不同的是需要在編譯時加入ldap認證的支持。

    2.1 先安裝gcc、ldap-devel、git等必備的軟件,用yum命令。

    2.2 下載ldap支持文件。


    git clone https://github.com/kvspb/nginx-auth-ldap.git


    2.3安裝配置nginx是,加入下面的ldap auth模塊,注意./ nginx-auth-ldap是ldap支持文件的目錄,必要時請改未您的目錄名。


    ./configure –add-module=./
    nginx-auth-ldap



    2.4 編譯安裝,其他請參看http://noc.lzit.edu.cn/wordpress/?p=1392或者https://blog.51cto.com/lovemjd/2564280

  4. 2.5 啓動nginx,這點與CentOS6上就不同了。

    先創建服務文件nginx.service。

    位置:/usr/lib/systemd/system/nginx.service

    內容:


    然後,無論是否修改該服務文件,只要打開,就需要重新導入,使用如下命令:

    systemctl daemon-reload

    最後用如下命令啓停及添加服務。

systemctl start nginx.service #啓動

systemctl stop nginx.service #停止

systemctl status nginx.service #查看狀態

systemctl enable nginx.service #開機啓動

ps –ef | prep nginx #查看進程

kill –s 9 進程號 #殺死進程

 

  1. 配置Nginx的反向代理支持LDAP Auth

     


    ldap_server test {

    url ldap://210.26.*.*:389/ou=*,dc=lzptc?uid?sub?(objectClass=inetOrgPerson);

    binddn “******”;

    binddn_passwd “*********”;

    group_attribute inetOrgPerson;

    group_attribute_is_dn on;

    require valid_user;

    }

     

    upstream lzitjpkc {

    server 210.26.16.44 max_fails=1 weight=1 fail_timeout=1;

    }

    server {

    server_name jpkc.lzit.edu.cn;

    listen 80;

    charset utf-8;

    location / {

    charset gbk;

    auth_ldap “Forbidden”;

    auth_ldap_servers test;

    proxy_pass http://lzitjpkc;

    }

    }

 

配置完成,保存配置,重新啓動nginx。

  1. 測試:

     


    輸入LDAP服務中預存的賬號密碼,登錄成功!

     

     

     

    以下是資料。

    認證順序:

    資料如下:

Syntax:

satisfy all | any;

Default:

satisfy all;


Context:

httpserverlocation

Allows access if all (all) or at least one (any) of the ngx_http_access_module,ngx_http_auth_basic_modulengx_http_auth_request_module, or ngx_http_auth_jwt_module modules allow access.

Example:


location / {
    satisfy any;
    allow 192.168.1.0/32;
    deny  all;
    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}


 

680be3150e39ef47c5892316f99494c6.pngconvert this post to pdf.

這篇文章發佈於 2017年11月16日,星期四,12:15 下午,歸類於 LDAP。 您可以跟蹤這篇文章的評論通過 RSS 2.0 feed。 您可以留下評論,或者從您的站點trackback


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章