mirroring http traffic

March 9, 2016 @ 11:59

Today I needed to figure out how to mirror 100% of inbound HTTP/HTTPS traffic to a second cluster of backend servers, whilst not disrupting the production traffic going to the primary cluster.

There's lots of tools to do things like this, for example duplicator and teeproxy and parallel-proxy. But those are all "code I found on the internet" and possibly questionable, and in some cases, written in node.js, which I don't know if I consider "mature" or "robust" enough for production traffic.

But there's a much better answer: nginx! It's simple:

server {
    listen 80;
    location @mirror {
        proxy_pass http://mirror.test.com;
    location / {
        proxy_pass http://primary.test.com;
        post_action @mirror;