Video not showing after implementing Nginx, without Nginx it works perfectly.

Hi, first of all thank you for this wonderful library. And sorry for this question, but I had no other choice, already spent 3 sleepless nights with this.
let me jump straight into the issue I am facing.
I have setted up the Mediasoup in nodejs which is running on Docker ( ubuntu ) & able to stream videos from both peers. But when I implement Nginx both the peers are unable to view there video. But both the Peers are receiving dtlsParamaters, iceCandidates didn’t throw any error.

Here is the complete github link - project link
branch name - implement-scalable-architecture
Here is my docker-compose file

version: "3.8"
services:
  mongodb:
    image: mongo:5.0.2
    restart: unless-stopped
    env_file: ./.env
    environment:
      - MONGO_INITDB_ROOT_USERNAME=$MONGODB_USER
      - MONGO_INITDB_ROOT_PASSWORD=$MONGODB_PASSWORD
    ports:
      - $MONGODB_LOCAL_PORT:$MONGODB_DOCKER_PORT
    volumes:
      - mongo-db:/data/db
    networks:
      - backend

  nginx:
    image: nginx:alpine
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./server/certificates/ssl:/etc/nginx/certs
    ports:
      - "3000:80"
      - "443:443"
      - "3001-3999:3001-3999"
    depends_on:
      - server
    networks:
      - backend
      - frontend

  redis:
    image: redis:alpine
    expose:
      - "6379"

  server:
    container_name: "airbooth-server-c"
    image: "airbooth-server-i"
    depends_on:
      - mongodb
    build:
      context: ./server
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file: ./.env
    tty: true
    expose:
      - "3000"
      - "3001-3999"
    environment:
      - DB_HOST=mongodb
      - DB_USER=$MONGODB_USER
      - DB_PASSWORD=$MONGODB_PASSWORD
      - DB_NAME=$MONGODB_DATABASE
      - DB_PORT=$MONGODB_DOCKER_PORT
      - CLIENT_ORIGIN=$CLIENT_ORIGIN
      - SERVER_NAME=server_one
    volumes:
      - ./server:/server/
      - server-node-modules:/server/node_modules
    networks:
      - backend
      - frontend

  client-airbooth-app:
    image: client-airbooth-i
    build:
      context: ./client/airbooth-app
      dockerfile: Dockerfile
    container_name: client-airbooth-c
    volumes:
      - ./client/airbooth-app:/client/airbooth-app
      - client-airbooth-app-node-modules:/client/airbooth-app/node_modules/
    ports:
      - "4006:5173"
    stdin_open: true
    environment:
      - NODE_ENV=development

  client-inspector-admin:
    image: client-inspector-admin-i
    build:
      context: ./client/inspector-admin
      dockerfile: Dockerfile
    container_name: client-inspector-admin-c
    volumes:
      - ./client/inspector-admin:/client/inspector-admin
      - client-inspector-admin-node-modules:/client/inspector-admin/node_modules/
    ports:
      - "4007:5174"
    stdin_open: true
    environment:
      - NODE_ENV=development
  client-IAM-app:
    image: client-iam-i
    build:
      context: ./client/IAM-app
      dockerfile: Dockerfile
    container_name: client-IAM-c
    volumes:
      - ./client/IAM-app:/client/IAM-app
      - client-IAM-app-node-modules:/client/IAM-app/node_modules/
    ports:
      - "4008:5173"
    stdin_open: true
    environment:
      - NODE_ENV=development
volumes:
  mongo-db:
  server-node-modules:
  client-airbooth-app-node-modules:
  client-inspector-admin-node-modules:
  client-IAM-app-node-modules:

networks:
  backend:
  frontend:

This is my NginX config file:

worker_processes 1;

events {
  worker_connections 1024;
}

http {
  server {
    listen 80 ssl;
    listen 3001-3999;

    ssl_certificate     /etc/nginx/certs/nginx-selfsigned.crt;
    ssl_certificate_key /etc/nginx/certs/nginx-selfsigned.key;

    location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;

      proxy_pass http://nodes;

      # enable WebSockets
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
  }

  upstream nodes {
    # enable sticky session with either "hash" (uses the complete IP address)
    hash $remote_addr consistent;
    # or "ip_hash" (uses the first three octets of the client IPv4 address, or the entire IPv6 address)
    # ip_hash;
    # or "sticky" (needs commercial subscription)
    # sticky cookie srv_id expires=1h domain=.example.com path=/;

    server server:3000;
    # server server-two:3000;
    # server server-three:3000;
  }
}

creating transport

const webRtcTransport_options = {
        listenIps: [
          {
            ip: "0.0.0.0", 
            announcedIp: "127.0.0.1",
          },
        ],
        enableUdp: true, 
        enableTcp: true,
        preferUdp: true,
      };

How are clients supposed to connect to this server? For them, 127.0.0.1 is the address of their local interface.

@snnz i’m running everything locally, not deployed to any cloud. Just a local docker setup.

Am I doing anything wrong here, because the same code with same announcedIp runs perfectly without Nginx.

If both clients and mediasoup are on the same system and the clients connect directly to 127.0.0.1, on which mediasoup is listening (ip 0.0.0.0 means listen on all interfaces, including 127.0.0.1), only then this works.

@snnz yes both clients are in the same system & local network.
Does Docker network affect this ?
I’m a front end guy with little knowledge in backend.

How docker network affects this depends on what network mode is used. Probably in host mode mediasoup server inside container binds to host’s 127.0.0.1, but mediasoup and nginx can’t both listen on the same address.

@snnz Thanks, based on my implementation Could you provide me any possible solution please.

After reading the docs & community replies this is what I understood, please let me know is this correct or not.
If I create a webrtctransport with announcedId:127.0.0.1 and port as 3002, mediasoup library will be listing in 127.0.0.1 & the client will try to reach the server by 127.0.0.1:3002 inorder to consume/produce media. This implementation without Nginx works because I directly expose and map my ports to host machine, did I understood correctly ?

If this is correct, then my question is even though my media soup server is behind docker containers network, still the client request 127.0.0.1:3002 will be forwarded by Nginx to my mediasoup server, but why isn’t working ?