# nginx configuration for mulTmux
# Place this in /etc/nginx/sites-available/multmux
# Then: sudo ln -s /etc/nginx/sites-available/multmux /etc/nginx/sites-enabled/

upstream multmux_api {
    server localhost:3000;
}

upstream multmux_ws {
    server localhost:3001;
}

server {
    listen 80;
    server_name your-server-domain.com;  # Change this to your domain or IP

    # HTTP API
    location /api {
        proxy_pass http://multmux_api;
        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;
        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;
    }

    # WebSocket
    location /ws {
        proxy_pass http://multmux_ws;
        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_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 86400;
    }
}

# Optional: SSL configuration (if using Let's Encrypt)
# server {
#     listen 443 ssl http2;
#     server_name your-server-domain.com;
#
#     ssl_certificate /etc/letsencrypt/live/your-server-domain.com/fullchain.pem;
#     ssl_certificate_key /etc/letsencrypt/live/your-server-domain.com/privkey.pem;
#
#     # Same location blocks as above...
# }
