Is it possible to mirror UDP traffic to two destinations?
Hello, r/nginx! Long story short, I am replacing a production system where nginx is proxying UDP packets from a public port to a private service port (on the same box). The essential bit of the configuration:
stream {
upstream backend { server 127.0.0.1:1234; }
server {
listen 5678 udp;
proxy_pass backend;
}
}
I would like to keep this proxy configuration active so as to not disturb the production system, and in addition mirror all incoming datagrams to a secondary destination (the purpose is to test the replacement system with real data..) But I have not found a way to accomplish this (I've never used nginx before though, could easily be overlooking something...)
It seems like I can add another server record in the upstream block to alternate between destinations, but can't find a way to configure it as "send to ALL of these servers". I also can't find any examples of using multiple proxy_pass in the server block (although the docs vaguely imply that it may be possible, "proxy_pass sets the address of a proxied server" - not the).. There is ngx_http_mirror_module but no obvious equivalent for UDP; I've also found some examples of using post_action for http, but not been able to find any UDP examples or come up with a configuration that passes nginx -t..
Any hints? Is this possible, or do I need to remove nginx from the equation altogether? Thanks!
ETA: to be clear, any dirty hack will do - this system is low-traffic and will only run for a few weeks... Maybe I could enable debug logging (with full datagram contents) and tail the logfile with a small code snippet that emits UDP packets?
ETA2: I will probably change listen 5678 udp to use a different port, and run samplicator on 5678 and forward to the new nginx port as well as the secondary destination. This seems like the least risky low effort solution, and it saves me writing the program...
Posted Mar 12, 2019, 10:06 AM UTC · edited