events{}
http {
    server_tokens off;
    client_max_body_size 200m;

    server {
        listen 11434;
        set $deny 1;
        if ($http_authorization = "Bearer $API_KEY") {
            set $deny 0;
        }
        if ($deny) {
            return 403;
        }
        location / {
            proxy_pass http://ollama:11434;
            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;
        }
    }
    server {
        listen 8000;
        set $deny 1;
        if ($http_authorization = "Bearer $API_KEY") {
            set $deny 0;
        }
        if ($deny) {
            return 403;
        }
        location / {
            proxy_pass http://openedai-speech:8000;
            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;
        }
    }
    server {
        listen 8001;
        set $deny 1;
        if ($http_authorization = "Bearer $API_KEY") {
            set $deny 0;
        }
        if ($deny) {
            return 403;
        }
        location / {
            proxy_pass http://faster-whisper-server:8000;
            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 180;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }
}
