我具有以下nginx配置来对/ admin请求进行身份验证:
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/;
}
认证流程本身似乎工作正常。
问题:如何记录在auth.php中经过身份验证的用户?我尝试如下在PHP中设置标头:
header("X-App-User: $user");
,然后在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;
但是,这似乎不起作用-远程用户未登录到access.log中。我在做什么错了?