I have the following nginx config to authenticate /admin requests :
location /admin {
auth_request /auth;
auth_request_set $auth_status $upstream_status;
error_page 401 = @error401;
}
location = /auth{
internal;
proxy_pass https://localhost/login/auth.php;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
location @error401 {
return 302 /login/;
}
The authentication flow itself seems to work fine.
Question : How do I log the user that is authenticated in auth.php? I have tried setting up a header in PHP as follows:
header("X-App-User: $user");
and then in nginx.conf :
log_format combined_with_proto '$scheme $remote_addr $remote_user $sent_http_x_app_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log combined_with_proto;
However that does not seem to work - the remote user is not logged in the access.log. What am I doing wrong?