Skip to content

How to Configure Nginx Mirror Module for Traffic Shadowing

DodaTech Updated 2026-06-24 2 min read

The mirror module duplicates production traffic to a secondary backend for testing without affecting real users. This guide walks through the specific troubleshooting steps to diagnose and resolve traffic mirroring issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

Using separate test environment (no real traffic)

Wrong: Testing without production traffic

location / {\n    mirror /mirror;\n    proxy_pass http://backend;\n}\nlocation = /mirror {\n    internal;\n    proxy_pass http://shadow-backend;\n}

Right: Mirroring production traffic to shadow backend

Output

Mirror module configured:\n  Original: http://backend\n  Mirror: http://shadow-backend\n  Errors from mirror ignored

Prevention

To avoid future issues, follow these best practices:

  • Use mirror for traffic shadowing without affecting real requests
  • The mirror location must be internal to prevent direct access
  • Mirror requests are fire-and-forget -- errors are ignored
  • Mirror supports request body with mirror_request_body on/off
  • Use for canary testing, migration validation, and performance testing

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with mirror

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world NGINX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How does the mirror module work?|||Nginx sends a copy of the request to the mirror location in addition to the original request. The mirror response is ignored.
Does mirroring affect performance? Mirror requests are asynchronous. The client waits only for the original backend response. Mirror failures do not affect the client.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro