0

I have a case where I would like nginx to proxy_pass queries to a backend and mirror it to one or more site.

That is quite straight forward with a config like

server {
        server_name mydomain.tld;
        listen 80;

        location /my/endpoint {
                mirror /mirror;
                proxy_pass http://mainbackend;
        }

        location /mirror {
                internal;
                proxy_pass http://mirrorbackend$request_uri;
        }
}

However, the main backend isn't ready yet, and I would like nginx to mirror the query and respond with 200.

I tried the following (and several variation as it didn't work)

server {
        server_name mydomain.tld;
        listen 80;

        location /my/endpoint {
                mirror /mirror;
                # proxy_pass http://mainbackend;
                return 200;
        }

        location /mirror {
                internal;
                proxy_pass http://mirrorbackend$request_uri;
        }
}

By doing so, nginx do return 200, but mirroring is not working.

I really want nginx to return 200 and not the mirrorbackend response because it's a test server that might be up or down and its state shouldn't impact the response given.

Can it be done ? How can I do that ?

jyte
  • 1

1 Answers1

0

it's not pretty, but it works

server {
    server_name mydomain.tld;
    listen 80;

    location /my/endpoint {
            mirror /mirror;
            proxy_pass http://mydomain.tld/OK/;
    }

    location /mirror {
            internal;
            proxy_pass http://mirrorbackend$request_uri;
    }

    location /OK/{
            return 200;
    }
 }
vix2
  • 1
  • Are you sur it works ? Because I am sure I tried that exact same thing, it returned 200 but I didn't see any mirrored query on the mirrorbackend log. For now I have a dummy express server that return 200 and the "main" proxypass forward to that... – jyte Feb 23 '22 at 09:57