I am trying to figure out a solution for this problem, unfortunately I am not much of an Nginx expert.
I am trying to figure a way to dynamically proxy to Docker containers that are running Nginx RTMP.
I would have the main Nginx image that does the "routing" and each of the RTMP instances would simply have their own configuration, allowing for each to be restarted without disturbing the others.
My question is: how?
I assume that I can dynamically route the RTMP request based on a "secret key" and then have it proxy to the appropriate port.
Something like?
server {
listen 1935;
chunk_size 4096;
notify_method get;
application live {
on_publish http://localhost/auth;
live on;
record all;
record_path /var/www/html/recordings;
record_unique on;
push rtmp://localhost:$dynport;
}
}
I am just unsure how to get the auth script to pass a port number to nginx.
You can use this project I created: https://github.com/spartanz51/rtmp-interceptor
And redirect user to different RTMP server based on their rtmp key
const RTMPInterceptor = require('rtmp-interceptor')
const params = {
listenPort: '1936'
}
RTMPInterceptor.listen(params, (client, tcUrl, SKey) => {
console.log('tcUrl: '+tcUrl) /* Do something with the data ... */
console.log('StreamKey: '+SKey)
return { /* Return false to block client and close stream */
host: 'localhost',
port: '1935'
}
})
This will redirect user to localhost:1935