RTMP Relay Help Please

So, I am now able to forward/relay and incoming rtmp stream to a container. Unfortunately I had to use
iptables on the host like this:

iptables -t nat -A PREROUTING -p tcp -i enp0s3 --dport 1935 -j DNAT --to-destination :1935

This works for one container. Well sorta. My container is getting the rtmp streams (.ts segment), but I cant play them from the internet for some reason. But that seems to be another issue that I need to work.

But anyway, the IPtables does me no good when I have multiple containers I could route to. Unless there is something with IPtables that will allow me to do this? (I doubt it)

But my bigger problem is I want to be able to route the incoming RTMP stream to a specific container based on the rtmp input. I’ve been playing around with the nginx.conf but can’t seem to figure out a working solution, if there is even one.

Any ideas how I can have the incoming rtmp stream treated like the iptables I showed, but forward the rtmp to a specific container based on the incoming rtmp stream url?



Not sure but perhaps ipset(s) with routing tables could do the trick.

You would need a proxy that checks the first packets of a new RTMP connection, and hopefully in those packets there are instructions as to which service the user wants to connect to.
I do not know whether RTMP has such a feature.
In any case, you can use HAProxy for such a task. HAProxy can be configured to check the first network packets and depending on their content, it can redirect to the appropriate container.
You would use iptables to divert all RTMP traffic to the haproxy container, then HAProxy will have rules that direct the traffic to the corresponding container.

Thanks Simos. I will give that a try.