nginx版本:1.10.2

nginx安装:
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_ssl_module --with-http_sub_module --with-http_auth_request_module --with-http_stub_status_module
make
make install
已安装nginx服务的话,通过 nginx -V 检查是否支持编译时是否添加 --with-http_auth_request_module,因为认证需要用到ngx_http_auth_request_module,如果不支持,需要重新编译添加(参考:https://anyof.me/articles/236)。

nginx的ldap认证需要通过nginx官方提供的服务去实现,首先需要把代码下载下来。
git clone https://github.com/nginxinc/nginx-ldap-auth
nginx-ldap-auth主要涉及的有两个脚本:
backend-sample-app.py:提供登录服务
nginx-ldap-auth-daemon.py:提供认证服务
脚本需要ldap模块支持: yum install python-ldap -y
backend-sample-app.py的登录界面会将密码明文显示,很不友好,将html内容替换成:

html="""
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8"/>
<title>登陆框</title>
</head>
<style>
*{margin:0;padding:0;}
.login{
width:334px;
height:220px;
margin:0 auto;
position:absolute;
left:40%;
top:40%;
}
.login_title{
color: #000000;
font: bold 14px/37px Arial,Helvetica,sans-serif;
height: 37px;
padding-left: 35px;
text-align: left;
} .login_cont {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #B8B7B7;
height: 152px;
padding-top: 30px;
}
.form_table {
float: left;
margin-top: 10px;
table-layout: fixed;
width: 100%;
}
.form_table th {
color: #333333;
font-weight: bold;
padding: 5px 8px 5px 0;
text-align: right;
white-space: nowrap;
}
.form_table td {
color: #717171;
line-height: 200%;
padding: 6px 0 5px 10px;
text-align: left;
}
.login_cont input.submit {
background-position: 0 -37px;
height: 29px;
margin: 10px 14px 0 0;
width: 82px;
}
</style>
<body>
<div class="login">
<div class="login_cont">
<form action='/login' method='post'>
<table class="form_table">
<col width="90px" />
<col />
<tr>
<th>用户名:</th><td><input class="normal" type="text" name="username" alt="请填写用户名" /></td>
</tr>
<tr>
<th>密码:</th><td><input class="normal" type="password" name="password" alt="请填写密码" /></td>
</tr>
<tr>
<th></th><td><input class="submit" type="submit" value="登录" /><input class="submit" type="reset" value="取消" /></td>
</tr>
</table>
<input type="hidden" name="target" value="TARGET">
</form>
</div>
</div>
</body>
</html>"""

接下来把两个脚本运行起来:
nohup python backend-sample-app.py > login.log 2>&1 &
nohup python nginx-ldap-auth-daemon.py --host 0.0.0.0 >auth.log 2>&1 &
脚本默认监听localhost,根据需要自行修改。

nginx ldap认证 配置
在需要认证的server里加入以下:

location / {
#auth_basic "Welcome to solr";
#auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
auth_request /auth-proxy;
error_page 401 403 =200 /login;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#需要认证的服务
proxy_pass http://dev-solr:8983;
}

location /login {
#登录服务
proxy_pass http://172.31.29.18:9000/login;
proxy_set_header X-Target $request_uri;
}

location = /auth-proxy {
internal;
#认证服务
proxy_pass http://172.31.29.18:8888;
proxy_cache_key "$http_authorization$cookie_nginxauth";
proxy_cache_valid 200 403 1m;

proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Ldap-URL "ldap://ldap.xxxx.net:389";
proxy_set_header X-Ldap-BaseDN "DC=ldap,DC=xxxx,DC=net";
#proxy_set_header X-Ldap-Template "(|(cn=xxxxx@xxxxx.com)(cn=xxxxx@xxxxxx.com))";
proxy_set_header X-Ldap-BindDN "cn=Manager,dc=ldap,dc=xxxxx,dc=net";
proxy_set_header X-Ldap-BindPass "xxxxxxx";
proxy_set_header X-CookieName "nginxauth";
proxy_set_header Cookie nginxauth=$cookie_nginxauth;
}

可以通过X-Ldap-Template配置ldap某个组的用户访问server:proxy_set_header X-Ldap-Template "(&(cn=%(username)s)(memberOf=cn=groupname,cn=Users,dc=ldap,dc=xxxxx,dc=com))";

但我这边配置后发现ldap 不支持 memberOf,需要手动开启。因为是一些内部服务,这边采用一个折中的方法,设置白名单方式限制访问。
缺陷:
不支持权限控制
管理账号明文显示,有风险(可以把账号配置在nginx-ldap-auth-daemon.py脚本里)

参考链接:https://sapser.github.io/devops/2016/07/22/nginx-ldap

ldap集成nginx的更多相关文章

  1. ldap集成bitbucket

    confluence ldap配置跟jira ldap集成一样,请参考:https://www.cnblogs.com/imcati/p/9378668.html 需在 Global permissi ...

  2. ldap集成jenkins

    jenkins版本:2.5.3,ldap插件:1.15 jenkins ldap支持需要安装ldap plugin,强烈建议插件安装版本为1.15及以上(支持ldap 配置测试) 安装插件: 系统管理 ...

  3. ldap集成confluence

    confluence ldap配置跟jira ldap集成一样,请参考:https://www.cnblogs.com/imcati/p/9378668.html

  4. CAS与LDAP集成

    参考文献: CAS集成ldap:https://wiki.jasig.org/display/CASUM/LDAP CAS集成restful api:https://wiki.jasig.org/di ...

  5. apache+svn+ldap集成

    apache+svn搭建方式如下:http://www.cnblogs.com/uglyliu/p/6914056.html SVN和ldap集成,我用的方式只需要更改 /etc/http/conf. ...

  6. 【Web】Rest && 权限管理 && LDAP && OAuth && Nginx && Lua 等

    最好的8个 Java RESTful 框架:http://www.importnew.com/17138.html 如何设计RESTful的API权限:https://segmentfault.com ...

  7. tomcat集群搭建集成nginx负载均衡

    软件基础+版本: 1.3台centos7系统,其中都已经配置完成了jdk环境,jdk的版本为 [root@node03 bin]# java -version java version "1 ...

  8. ldap 集成harbor

    harbor: 1.6 默认配置文件在harbor.cfg,我们可以先不添加配置,直接在harbor web界面进行配置(harbor 1.6 如果db 启动失败提示postgresql 数据目录已存 ...

  9. ldap集成grafana

    grafana版本: 5.0.3 grafana通过k8s方式安装,所以需将配置文件挂载过去. cat grafana-configmap.yaml apiVersion: v1 kind: Conf ...

随机推荐

  1. 7.C# 多态的实现

    C# 多态的实现 封装.继承.多态,面向对象的三大特性,前两项理解相对容易,但要理解多态,特别是深入的了解,对于初学者而言可能就会有一定困难了.我一直认为学习OO的最好方法就是结合实践,封装.继承在实 ...

  2. node.js初识09

    1.node_module文件夹 如果你的require中没有写./,那么Node.js将该文件视为node_modules目录下的一个文件. 2.package.json文件 如果使用文件夹来统筹管 ...

  3. [提权] 脏牛漏洞 Dirty COW CVE-2016-5195 2.6.22 < 3.9 (x86/x64)

    /* * (un)comment correct payload first (x86 or x64)! * * $ gcc cowroot.c -o cowroot -pthread * $ ./c ...

  4. Lambda表达式语法

    基础语法:‘->’Lambda操作符* 左侧:Lambda表达式的参数列表 对应接口中方法中的参数列表中的参数(比如nice1中MyPredict这个接口中的方法)* 右侧:Lambda表达式中 ...

  5. 切记!pycharm向mysql数据库添加数据过程

    python 导入包import requests   以爬取腾讯招聘网的招聘信息为例:(完整代码) import requestsfrom lxml import etreeimport pymys ...

  6. 关于hdfs 和hive的数据迁移

    1. 迁移hdfs,使用hadoop 命令 hadoop distcp -pugp  hdfs://localhost:9000/ hdfs://localhost:9000/ 此处示例仅作说明用 2 ...

  7. python ---多线程thread

    thread 在数据预处理的时候用处不大,因为有GIL 锁 查看thread信息 import threading print(threading.current_thread()) print(th ...

  8. Yii2 数据缓存/片段缓存/页面缓存/Http缓存

  9. [转] LoadRunner 获取接口请求响应信息

    Action() { int nHttpRetCode; // 默认最大长度为256,get请求需注意缓存问题,需要根据content-length进行修改 web_set_max_html_para ...

  10. Java多线程-----线程池详解

    1. 线程池的实现原理 提交一个任务到线程池中,线程池的处理流程如下: 判断线程池里的核心线程是否都在执行任务,如果不是(核心线程空闲或者还有核心线程没有被创建)则创建一个新的工作线程来执行任务.如果 ...