如何从表单中获取用户名并通过nginx传递用户名?

时间:2018-07-06 04:42:28

标签: nginx ldap

我逐步遵循reference(https://www.nginx.com/blog/nginx-plus-authenticate-users/)来集成ldap和nginx身份验证。

现在,我想从登录表单中提取用户名,并将其通过nginx传递。 还是python可以将x-proxy-header传递给指定的ip:port?

nginx-ldap-auth-daemon.py,backend-sample-app.py,nginx-ldap-auth-daemon-ctl-rh.sh是默认设置。 nginx.conf:

    error_log logs/error.log debug;
    events {
    worker_connections 10240;
    }
    http {
        proxy_cache_path cache/  keys_zone=auth_cache:10m;
        upstream backend {
            server 127.0.0.1:9000;
            #server 127.0.0.1:5601;
        }
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        server {
            listen 8081;
            location / {
                auth_request /auth-proxy;
                error_page 401 =200 /login;
                proxy_set_header X-PROXY-USER $username;       //how to get the username in nginx?
                #proxy_pass http://backend/;
                proxy_pass http://localhost:5601;
            }
            location /login {
                proxy_pass http://backend/login;
                proxy_set_header X-Target $request_uri;
            }


location = /auth-proxy {
            internal;
            proxy_pass http://127.0.0.1:8888;
            proxy_pass_request_body off;
            proxy_set_header Content-Length "";
            proxy_cache auth_cache;
            proxy_cache_valid 200 10m;
            proxy_cache_key "$http_authorization$cookie_nginxauth";
            proxy_set_header X-Ldap-URL      "ldap://localhost:389";
            proxy_set_header X-Ldap-BaseDN   "dc=xinhua,dc=org";
            proxy_set_header X-Ldap-BindDN   "cn=Manager,dc=xinhua,dc=org";
            proxy_set_header X-Ldap-BindPass "xxxxxx";
            proxy_set_header X-CookieName "nginxauth";
            proxy_set_header Cookie nginxauth=$cookie_nginxauth;
        }
    }
}

enter image description here

0 个答案:

没有答案