mirror

The `mirror` directive in NGINX is used to create a duplicate request for a specified upstream server, effectively mirroring incoming requests to the backend without affecting the original response. — NGINX HTTP Core

mirror
httpserverlocation
Синтаксисmirror ;
По умолчаниюnone
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1

Описание

The `mirror` directive allows a server to send a duplicate request of the original request to a backend server. This can be useful for various purposes such as logging, performance monitoring, or testing without impacting the original user experience. When this directive is used in an HTTP context (http, server, or location), it specifies the URL of the upstream server that will handle the mirrored request. In practical use, when a request is received, NGINX processes it as usual and then, in parallel, sends an exact copy of this request to the configured upstream server defined in the `mirror` directive. This means the main request's response and the mirrored request's response can operate independently. Specifying the correct upstream server is crucial to ensure that the mirrored request functions as intended. One of the significant aspects to consider with the `mirror` directive is that it does not wait for the response from the mirrored request; therefore, any feedback from the upstream server regarding the mirrored request does not influence the user's original request. This feature can lead to performance considerations since the mirrored requests effectively double the traffic to the backend server specified.

Пример конфига

location /example {
    mirror /backend;
}

location = /backend {
    internal;
    proxy_pass http://backend-server;
}

The target of the mirror request must be specified properly; an incorrect URL will cause issues in the mirroring process.

Remember that mirrored requests do not affect the original response; be cautious if the backend is intended to be stateful.