events {
    worker_connections 512;
}
http {
    upstream openvidu-deployment {
        server host.docker.internal:4443;
    }
    upstream server-application {
        server host.docker.internal:5000;
    }
    upstream client-application {
        server host.docker.internal:8080;
    }
    server {
        listen                  443 ssl;
        ssl_certificate         /etc/nginx/certs/cert.pem;
        ssl_certificate_key     /etc/nginx/certs/key.pem;

        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_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Proto https;
        proxy_headers_hash_bucket_size 512;
        proxy_redirect off;

        # Websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # OpenVidu deployment API
        location /openvidu/api {
            proxy_pass http://openvidu-deployment;
        }

        # OpenVidu WebSocket
        location ~ /openvidu$ {
            proxy_pass http://openvidu-deployment;
        }

        # Server application requests
        location /api/ {
            proxy_pass http://server-application;
        }

        # Client application requests
        location / {
            proxy_pass http://client-application;
        }
    }
}