nginx auth_request-在PHP脚本中进行身份验证后记录已身份验证的用户

时间:2018-12-19 12:02:04

标签: php nginx auth-request

我具有以下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中。我在做什么错了?

0 个答案:

没有答案