LDAP应用篇(3)Nginx接入

实验环境:Oracle Linux R8

在搞Nginx比较错愕的是,居然 Nginx 并未内置对LDAP的支持,需要单独编译。然而 yum 安装的 nginx 并不支持导入模块,不得不再次温习一下编译安装 Nginx 的路数了。

下载组件

github 中下载组件的源代码:

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

部署Nginx

环境准备

yum install openssl openssl-devel pcre-devel make autoconf gcc gcc-c++ -y

编译

./configure  --user=nginx --group=nginx --prefix=/etc/nginx \
--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
--with-http_ssl_module --with-http_v2_module --with-http_addition_module \
--with-http_gzip_static_module --with-http_random_index_module \
--add-module=/root/soft/nginx-auth-ldap

要注意的是,这里的编译,是编译nginx而不是组件本身。编译后的返回路径提示为:

nginx path prefix: "/etc/nginx"
nginx binary file: "/etc/nginx/sbin/nginx"
nginx modules path: "/etc/nginx/modules"
nginx configuration prefix: "/etc/nginx/conf"
nginx configuration file: "/etc/nginx/conf/nginx.conf"
nginx pid file: "/etc/nginx/logs/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

配置

Nginx 的主配置文件的 http 指令中,添加下面的配置段:

ldap_server test1 {
  url ldaps://server.example.com:636/dc=example,dc=com?uid?sub?(objectClass=*);
  binddn "cn=admin,dc=example,dc=com";
  binddn_passwd "123456";
   memberuid;
  group_attribute_is_dn on;
  require valid_user;
}

上面这段配置没有太闹明白其含义,比如 group_attribute 的值组件的文档中用的是 uniquemember,而一般能搜到的文章都是用的 memberuid ,根据对属性的反复对比,这应该就是默认的过滤配置,及具备了该组属性的用户方可登入。当然这也只是猜测,没有看到明确的说明出处!

根据常规对 Nginx 的管理,至少可以判断出上面的块配置,相当于定义了一个指令,因此可以在后面的相应位置,比如 server 或者 location 指令中进行配置,如果在同一个 server 指令范围内都进行了引用,则后者会覆盖前者的配置:

server {
    auth_ldap "Forbidden";
    auth_ldap_servers test1;
}

参考资料

posted @ 2024-07-17 22:29  雨帝夜泪  阅读(6)  评论(0编辑  收藏  举报