Closed Lisinder closed 2 years ago
This is a live example of my Wiki:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name notes.hub.luzifer.io;
ssl_certificate /data/ssl/nginxle/luzifer.io.pem;
ssl_certificate_key /data/ssl/nginxle/luzifer.io.key;
error_page 401 = @error401;
location / {
auth_request /sso-auth;
auth_request_set $cookie $upstream_http_set_cookie;
auth_request_set $username $upstream_http_x_username; # <-----
proxy_set_header X-WEBAUTH-USER $username; # <-----
add_header Set-Cookie $cookie;
proxy_pass http://127.0.0.1:1160;
}
location /sso-auth {
internal;
proxy_pass http://127.0.0.1:1730/auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Application "notes-wiki";
}
location @error401 {
return 302 https://login.luzifer.io/login?go=$scheme://$http_host$request_uri;
}
}
The application takes the username from the X-WEBAUTH-USER
header. (Marked the important lines)
Thank you, I was blind :smile: It works
Hi, I start using your tool and it is a really useful tool, thank you for it. But I need to put the user name who was authenticated to the Nginx header. Is there some chance how to do it? I am not so experienced with Nginx. Thank you.