Mirroring Traffic with Nginx

Solution 1:

Nginx now has an http mirror module. Documentation is at https://nginx.org/en/docs/http/ngx_http_mirror_module.html

Example configuration from the documentation:

location / {
    mirror /mirror;
    proxy_pass http://backend;
}

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

Solution 2:

Here is new feature from nginx (1.13.4): http://nginx.org/en/docs/http/ngx_http_mirror_module.html#mirror

The ngx_http_mirror_module module (1.13.4) implements mirroring of an original request by creating background mirror subrequests. Responses to mirror subrequests are ignored.

Solution 3:

Based on their README It looks that GOR could help you solving your problem.

I never used it before, just stumbled upon it this week, so good luck!

Solution 4:

you cannot mirror requests with NGINX but the request is available as a variable. You could use Lua scripting to send that variable to a third party server as a sub request though. http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request