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 Answers 2

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 /"? Commented Jul 24, 2018 at 12:29
  • @SergeyDi the same, as in your example.
    – Alexey Ten
    Commented Jul 24, 2018 at 14:44
  • If request will not delivered to "# mirror server", how I will know about this? Commented Jul 24, 2018 at 14:59
  • What do you mean?
    – Alexey Ten
    Commented Jul 25, 2018 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
    Commented Dec 23, 2019 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. Commented Feb 24, 2021 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .