nginx认证走LDAP
admin
2023-03-13 07:41:23
0

使用nginx走ldap认证:


将原nginx进行备份:

[root@daya-02 nginx-1.12.2]# mv /usr/sbin/nginx /usr/sbin/nginx.bak
[root@daya-02 nginx-1.12.2]# cp -r /etc/nginx/ /etc/nginx_bak


查看当前安装好的nginx版本:

[root@daya-02 ~]# nginx -V
nginx version: nginx/1.12.2


下载相同版本的源码包:

[root@daya-02 ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@daya-02 ~]# tar xf nginx-1.12.2.tar.gz


下载ldap需要的扩展包:

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


查看原nginx的编译参数:

[root@daya-02 nginx-1.12.2]# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'


再次编译就需要原来的编译参数加上需要添加的参数就好:

[root@daya-02 nginx-1.12.2]# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E' --add-module=/root/nginx-auth-ldap


然后执行make,只make就好不用install

检查是否可用:

[root@daya-02 nginx-1.12.2]# ./objs/nginx -t

进行替换:

[root@daya-02 nginx-1.12.2]# cp ./objs/nginx /usr/sbin/

重启:

[root@daya-02 nginx-1.12.2]# nginx -s reload


配置ldap认证:

    ldap_server test {
        url ldap://172.16.28.180:389/DC=test,DC=com?cn?sub?(objectClass=person);
        binddn "cn=admin,dc=test,dc=com";
        binddn_passwd 123465;
        #group_attribute People;
        #group_attribute_is_dn on;
        require valid_user;
    }
    server {
        listen       8080;
        server_name  _;
        root         /usr/share/nginx/html;
        location / {
            auth_ldap "Forbidden";
            auth_ldap_servers test;
        }
    }


遇到问题:以下都是环境上缺少相关的依赖,安装即可

./configure: error: the HTTP XSLT module requires the libxml2/libxslt
yum install libxslt-devel -y

./configure: error: the HTTP image filter module requires the GD library.
 yum install gd-devel -y
 
 ./configure: error: perl module ExtUtils::Embed is required
 yum -y install perl-devel perl-ExtUtils-Embed
 
./configure: error: the GeoIP module requires the GeoIP library.
 yum -y install GeoIP GeoIP-devel GeoIP-data
 
./configure: error: the Google perftools module requires the Google perftools
yum install gperftools -y

./configure: error: SSL modules require the OpenSSL library.
yum -y install openssl openssl-devel

checking for --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E" ... not found
./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"
yum install redhat-rpm-config -y

./configure: error: perl module ExtUtils::Embed is required
yum -y install perl-devel perl-ExtUtils-Embed

在执行make时候的报错:
/root/nginx-auth-ldap/ngx_http_auth_ldap_module.c:33:18: fatal error: ldap.h: No such file or directory
 #include 
yum install -y openldap-devel


相关内容

热门资讯

为190元“仅退款”榴莲千里讨... 极目新闻记者 王鹏因为一笔190元的恶意“仅退款”订单,卖家自掏5000余元,驱车1600公里赴山东...
“AI智能回答”误称律师“被判... 据澎湃新闻报道,南京执业律师李小亮发现,在百度手机App、百度网站搜索其个人姓名+职务时,百度“AI...
年初铺的草皮五一咋又铲除?自然... 江西省上饶市的周先生近日向华商报大风新闻反映:今年五一假期时,他注意到上饶市广丰区北河滨路芦林街道源...
浏阳烟花厂爆炸事故4名重症患者... 截至今天(9日)上午11时,浏阳烟花厂爆炸事故在院患者42人,原5名重症患者中4人已转为轻症;在院患...
中东战火不断,为何全球股市不跌... 最近与一位美国学者交流,他讲到一个颇有意味的场景:在华尔街一场交流中,包括他在内的3位国际问题研究专...
景区回应“母亲节穿旗袍免费入园... 近日,南京天生桥景区推出的母亲节当天女士穿旗袍免费入园活动引发争议,有人认为母亲节女士穿旗袍活动,策...
一本正经胡说八道,谁为AI幻觉... AI幻觉频发,误导用户、毁损名誉的责任,该由谁来承担?南京律师李小亮在百度上搜索自己的信息,结果百度...
老人在直播间疯狂刷火箭 周佳欣、郑凯丹、朱娅、蒋婉、黄铃、王佳、李婉晴/文64岁的王雅达又往直播间里刷了一枚“火箭”。屏幕上...
汉坦病毒阳性乘客在乌斯怀亚港登... 自世卫组织(WHO)5月6日公布荷兰泛海探险公司(Oceanwide Expeditions)旗下极...
冰箱不制冷的原因有哪几种 冰箱的电压在正常的情况下,压缩机没有正常的运转,而且有噪声和旋转的声音,压缩机一旦出现故障,冰箱就会...