Score:0

Nginx mirroring without "main" proxy_pass

jp flag

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 ?

Score:0
cn flag

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;
    }
 }
jyte avatar
jp flag
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...
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.