question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get username from the form and pass it through nginx?

See original GitHub issue

Hi, I want to extract username from the login form, and pass it through nginx. the nginx-ldap-auth-daemon.py, backend-sample-app.py, nginx-ldap-auth-daemon-ctl-rh.sh are default. 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;
        }
    }
}

thank you in advance!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Howard-Changcommented, Jul 7, 2018

I solved the problem thx 😃

0reactions
kjothcommented, Sep 22, 2020

@Howard-Chang how did you solve it? Can you brief it? I’m facing a similar situation for Nginx-LDAP authentication.

Also what should be provided in the nginx config for ? proxy_set_header X-Ldap-BindDN “cn=Manager,dc=xinhua,dc=org”; proxy_set_header X-Ldap-BindPass “9ol./;p0”;

Read more comments on GitHub >

github_iconTop Results From Across the Web

pass or write the username from Nginx into an app
I can see the user names in logs/nginx_shiny_access.log because of $remote_user . How can I get the user names in html file and...
Read more >
tomcat - nginx proxy based on username
I'm using nginx as a proxy server in front of Tomcat instances. There's basic authentication set up, giving access to the demo page...
Read more >
Restricting Access with HTTP Basic Authentication
You can restrict access to your website or some parts of it by implementing a username/password authentication. Usernames and passwords are taken from...
Read more >
How To Set Up Password Authentication with Nginx on ...
To start out, we need to create the file that will hold our username and password combinations. You can do this by using...
Read more >
Use nginx to Add Authentication to Any Application
Why Authenticate at the Web Server? · Using the nginx auth_request Module · Choosing an Auth Proxy · Configure Your Protected nginx Host...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found