Hello everyone, I apologize for asking this question but I’ve been stuck over this for many days.
Basically, I’m trying to deploy my application on AWS EC2 instance. I am using docker-compose and nginx for creating multiple replicas of the same server to balance the load between.
And everything is working fine (signalling and stuff) but my webrtc transport are not conneting when I’m using the load balancer. It works when I deploy the same project with only one replica but as soon as I create multiple versions of it, the transport doesn’t connect anymore.
And I am pretty sure it has something to do with rtcMin and rtcMax ports of mediasoup worker not being exposed properly but I can’t figure out a way to do it
Following are my relevant files
docker-compose.yml
version: '3'
services:
nginx:
build: ./nginx
ports:
- "8000:8000"
depends_on:
- backend
networks:
- my_network
backend:
build:
context: ~/Live-streaming/live-streaming-v2
hostname: server1
ports:
- "8000"
- "10000-10020/udp"
networks:
- my_network
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
volumes:
- /usr/bin:/usr/bin
- /usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu
- /usr/share:/usr/share
environment:
- RTC_MIN_PORT=10000
- RTC_MAX_PORT=10020
networks:
my_network:
driver: bridge
nginx configurations
upstream backend {
ip_hash;
server backend:8000;
}
server {
listen 8000;
# Handle general HTTP traffic with load balancing
location / {
proxy_pass http://backend;
proxy_connect_timeout 5s;
proxy_read_timeout 10s;
proxy_send_timeout 10s;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
# Forward client IP address to the backend
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
# Handle WebSocket connections for Socket.IO
location /socket.io/ {
proxy_pass http://backend; # Same upstream as regular traffic
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
# Optional timeout adjustments for WebSocket
proxy_read_timeout 60s;
proxy_send_timeout 60s;
# Log for debugging WebSocket issues
error_log /var/log/nginx/socketio_error.log;
access_log /var/log/nginx/socketio_access.log;
}
}
Dockerfile
FROM node:18
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 8000
CMD ["npm", "start"]
Thanks a lot for taking your time to read this