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


相关内容

热门资讯

在泰国GMM书展活动中遭锁喉、... 7月25日,一名中国女粉丝在泰国曼谷GMM书展活动中遭工作人员锁喉、抱摔等暴力对待。当事人称随后前往...
中国驻菲律宾大使:过去半年,我... 近日,中国驻菲律宾大使井泉接受看看新闻Knews独家采访,直面仁爱礁、黄岩岛海上争端、中菲关系走向、...
三预警齐发,台风“红霞”减弱为... 中央气象台7月26日10时继续发布台风黄色预警、暴雨红色预警和强对流天气黄色预警。台风黄色预警“红霞...
痛批民进党是台湾的敌人,侯汉廷... 海峡导报综合报道 国民党25日号召支持者上台北凯达格兰大道,举办“我是人、我反毒台”集会游行,主办方...
甘肃白银警方侦破一起16年前的... 澎湃新闻记者 吕鑫7月26日,甘肃省公安厅官方微信公众号文章披露,近日,白银市公安局平川分局命案攻坚...
音乐作品被白宫用于宣传打击伊朗... 据美国《国会山报》《华盛顿邮报》等多家媒体报道,美国流行歌手“水果姐”凯蒂·佩里当地时间25日在社交...
特朗普暂停空袭,美媒曝光核心原... 据《纽约时报》报道,在连续13晚对伊朗发动袭击后,7月25日,美军没有宣布任何夜间打击行动。据知情人...
一年内18次操纵证券市场,方某... 7月24日,根据中国证券监督管理委员会山东监管局发布的行政处罚决定书,方某军因一年内18次操纵市场的...
电热水器红色蓝色那里漏水 因为电热水器的发热器密封圈出现了破损,就会导致红色蓝色那里漏水;也有可能是由于电热水器的内胆出现了故...
电热水器漏水弹出一个圆片 可能是密封圈,是因为漏水造成这一部位出现问题,如果刚开始仅仅是滴水,慢慢的相邻的位置就开始出现侵蚀,...