Chris Bao
Chris Bao

Reputation: 2868

nginx: why no access log for rediect location

My nginx config file goes following:

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. 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. If I send request to /authVerify directly, there will be loggings as well.

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. After this change, the logs of internal rediect was produced, but the log of original mysite location disappear.

Currently after I send one request to /mysite, the log is as following:

enter image description here

I found the following explanation on 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

Is that because of that? Any more methods to log the request's entire flow?

Upvotes: 0

Views: 1674

Answers (1)

Rodrigo Albuquerque
Rodrigo Albuquerque

Reputation: 66

Have you tried enabling 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

Upvotes: 1

Related Questions