menu

Questions & Answers

location mirroring is not working when used with nginx redirect

I'm trying to redirect a URL with nginx and at the same time, mirror the request to another location block. the mirror works fine when I use it with proxy_pass, but it doesn't work when used with nginx redirect

location / {
    mirror /test
    access by lua '
    ngx.redirect("some url received from redis using lua scripts")
    '
}
location /test {
    proxy_pass <backend-service>
}
Answers(1) :

It looks like we can't use the mirror with the nginx redirect because the mirror gets triggered in phase PRECONNECT which occurs later than phase REWRITE where rewrite/return end request processing. So, the mirror does not even get triggered because its processing would happen later. Thanks to Alexander Azarov for explaining it in this question