简体   繁体   English

nginx:为什么没有重定向位置的访问日志

[英]nginx: why no access log for rediect location

My nginx config file goes following:我的 nginx 配置文件如下:

server {        
    location /mysite {
        auth_request /authVerify;
        proxy_pass http://localhost:4200;
        error_page 401 = /login;
    }

    location /authVerify {
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Original-URI $request_uri;
        proxy_pass http://localhost:3000;
    }

    location /login {
        proxy_cookie_path / "/; HttpOnly";
        proxy_pass http://localhost:3000;
    }

    location / {
        root   html;
        index  index.html index.htm;
    }
}

log related configs use the default settings.日志相关配置使用默认设置。

the auth_request configration works. auth_request配置有效。 But when I send request to /mysite , there is only logging of it in access log, there is no logging of /authVerify although it actually proxy through this locatoin.但是,当我向/mysite发送请求时,只有在访问日志中记录它,没有记录/authVerify虽然它实际上是通过此位置代理的。 If I send request to /authVerify directly, there will be loggings as well.如果我直接向/authVerify发送请求,也会有/authVerify

So in the redirect cases how to produce logs for all the locations the request running through?那么在重定向情况下,如何为请求运行的所有位置生成日志?

Update Based on the comment, I set log_subrequest as on in http block level.更新根据评论,我在http块级别将log_subrequest设置为 on。 After this change, the logs of internal rediect was produced, but the log of original mysite location disappear.更改后,内部转发的日志产生了,但原mysite位置的日志消失了。

Currently after I send one request to /mysite , the log is as following:目前我向/mysite发送一个请求后,日志如下:

在此处输入图片说明

I found the following explanation on nginx doc:我在 nginx doc 上找到了以下解释:

Requests are logged in the context of a location where processing ends. It may be different from the original location, if an internal redirect happens during request processing.

http://nginx.org/en/docs/http/ngx_http_log_module.html http://nginx.org/en/docs/http/ngx_http_log_module.html

Is that because of that?是因为那个吗? Any more methods to log the request's entire flow?还有更多方法可以记录请求的整个流程吗?

Have you tried enabling log_subrequest?您是否尝试过启用 log_subrequest?

log_subrequest

Context: http, server, and location

Enables or disables logging of sub-requests triggered by internal redirects or SSI requests.

Syntax: on or off

Default value: off

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM