1

I have nginx server with configuration:

location / {
    mirror /mirror;
    proxy_pass http://backend;
}

location = /mirror {
    internal;
    proxy_pass http://test_backend;
}

Everything works perfect, except one thing. I need to log, that mirrored request delivered. If mirrored request not delivered, I need to get some error in log file. How to do this?

2

I would use another server in the middle.

# main server
server {
    location / {
        mirror /mirror;
        proxy_pass http://backend;
    }

    location = /mirror {
        internal;
        proxy_pass http://127.0.0.1:55555;
    }
}

# mirror server
server {
    listen 127.0.0.1:55555;
    location / {
        proxy_pass http://test_backend;
        # whatever you want to log
        access_log ....;
        error_log ....;
    }
}
4
  • How "location = /mirror" will be executed from "location /"? – Sergey Di Jul 24 '18 at 12:29
  • @SergeyDi the same, as in your example. – Alexey Ten Jul 24 '18 at 14:44
  • If request will not delivered to "# mirror server", how I will know about this? – Sergey Di Jul 24 '18 at 14:59
  • What do you mean? – Alexey Ten Jul 25 '18 at 11:07
0

May be http://nginx.org/ru/docs/http/ngx_http_core_module.html#log_subrequest could help

log_subrequest on;

2
  • Hi, please include more detail from the link in case the link die with time. Thanks! – yagmoth555 Dec 23 '19 at 14:52
  • This comment was useful for me as I wasn't really aware of log_subrequest setting. It does what it says. :) I see another line in the access logs that was made as a sub request. – tunix Feb 24 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.