server {
    listen 80;
    server_name asf-testarena.duckdns.org;

    # Frontend Static Files
    location / {
        root /var/www/testarena;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    # Backend API Proxy
    location /api/ {
        proxy_pass http://localhost:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /auth/ {
        proxy_pass http://localhost:8000/auth/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /admin/ {
        proxy_pass http://localhost:8000/admin/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /jobs/ {
        proxy_pass http://localhost:8000/jobs/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    # WebSocket Proxy
    location /ws/ {
        proxy_pass http://localhost:8000/ws/;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
    }

    # Results (Assuming you mount/copy results to this path or proxy to backend if it served them)
    # The backend was configured to write to /results. 
    # Since we are running backend in docker, we mapped ./results to /results.
    # You can alias this location to the local folder on your PC.
    location /results/ {
        alias /path/to/your/project/testarena/results/;
        autoindex on;
    }
}
