Nginx如何支持LDAP认证

  1. 安装Centos7.0
    php

    最小版安装时,注意自行生成ifcfg-eth0,并设置DNS,主机名。
    html

    几个地址:
    nginx

    /etc/sysconfig/network-scripts
    git

    /etc/sysconfig/network
    github

    /etc/resolv.conf
    ide

    Yum安装net-tools,CentOS7默认没有ifconfig。
    wordpress

    关闭防火墙,CentOS默认不是iptables是Firewall:
    post

    systemctl stop firewalld.service #中止firewall
    测试

    systemctl disable firewalld.service #禁止firewall开机启动
    ui

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

    安装方法参考我以前的博客http://noc.lzit.edu.cn/wordpress/?p=1392或者http://www.javashuo.com/article/p-eobabnpf-ny.html

  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或者http://www.javashuo.com/article/p-eobabnpf-ny.html

  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