Hi Everyone,
I am currently facing an issue with UDP port conflicts while connecting to different backend servers through a load balancer. This setup involves a Mediasoup application and an Nginx server deployed on an EC2 instance within a Docker Compose environment. The problem arises when attempting to establish a group conference connection through the Nginx load balancer. The UDP ports are not properly routed across all backend servers configured in Nginx, leading to errors such as “Transport connection failed.”
The main concern is that the same UDP port cannot connect simultaneously to multiple backend servers during a group conference session. This conflict disrupts the communication between servers and prevents the application from functioning as expected.
I would greatly appreciate any insights or suggestions to resolve this issue and ensure seamless connectivity across all backend servers in the load-balanced environment.
Ubuntu Folders and files: Room-conferencing docker-compose.yml nginx
docker-compose.yml:
version: '3.8'
services:
nginx:
build: ./nginx
ports:
- "8080:80"
depends_on:
- backend1
- backend2
- backend3
networks:
- my_network
backend1:
build:
context: ./Room-conferencing/group-conference
hostname: server1
ports:
- "90:3000"
- "32769-32770:32769-32770/udp"
environment:
- RTC_MIN_PORT=32769
- RTC_MAX_PORT=32770
networks:
- my_network
backend2:
build:
context: ./Room-conferencing/group-conference
hostname: server2
ports:
- "94:3000"
- "32771-32772:32771-32772/udp"
environment:
- RTC_MIN_PORT=32771
- RTC_MAX_PORT=32772
networks:
- my_network
backend3:
build:
context: ./Room-conferencing/group-conference
hostname: server3
ports:
- "93:3000"
- "32773-32774:32773-32774/udp"
environment:
- RTC_MIN_PORT=32773
- RTC_MAX_PORT=32774
networks:
- my_network
networks:
my_network:
driver: bridge
Nginx/default.conf:
upstream loadBalancerControl {
ip_hash;
server backend1:3000;
server backend2:3000;
server backend3:3000;
}
server {
listen 80;
server_name 3.110.196.141;
location / {
proxy_pass http://loadBalancerControl;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
location /socket.io/ {
proxy_pass http://loadBalancerControl;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Nginx/Dockerfile:
FROM nginx:1.24.0
RUN rm /etc/nginx/conf.d/default.conf
COPY ./default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
Room-conferencing/group-conference/Dockerfile:
FROM node:18
WORKDIR /app
# Install necessary libraries
RUN apt-get update && apt-get install -y \
libssl-dev \
libsrtp2-dev \
&& rm -rf /var/lib/apt/lists/*
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
EXPOSE 32769-65535/udp
CMD ["npm", "start"]