Nginx reverse proxy relaying to multiple servers

nginxreverse-proxy

I want an incoming request from Nginx to be relayed to our production and staging server at the same time. How could I do this?

This is my current configuration:

server {
  listen 8000;
  proxy_redirect   off;

  location /mailjet/callback {
    post_action @post_for_first_mirroring;
    proxy_pass http://www.example.org;
  }
  location @post_for_first_mirroring {
    proxy_pass http://staging.example.org;
    proxy_ignore_client_abort on;
    return 200;
  }
}

However requests are not hitting my app at staging.mydomain.org. What else can I try?

Best Answer

The mirror module:

https://nginx.org/en/docs/http/ngx_http_mirror_module.html#mirror

is helpful but its use involves changing production configuration, and also giving your prod nginxes more work, neither of which may be desirable.

Also, sometimes you want to slightly change the replicated requests on their way to non-prod. The best tool for doing all of the things involved in replicating traffic in real time from prod to another environment is goreplay:

https://goreplay.org/