File size: 1,510 Bytes
f3aa131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ============================================================================
# HF Spaces nginx config — single-container variant.
# Difference from docker/nginx.conf: listens on 7860 (HF's expected port) and
# proxies /api/* to 127.0.0.1:8000 (same-container uvicorn, not a compose
# service name).
# ============================================================================
server {
    listen       7860;
    server_name  _;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript
               application/xml+rss text/javascript image/svg+xml;
    gzip_min_length 1024;

    # Vite-fingerprinted assets — long cache.
    location /assets/ {
        root /var/www/html;
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Proxy the API — uvicorn is running in the same container, port 8000.
    location /api/ {
        proxy_pass         http://127.0.0.1:8000/;
        proxy_http_version 1.1;
        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_connect_timeout 10s;
        proxy_read_timeout    120s;
        client_max_body_size  20m;
    }

    # SPA fallback — everything else goes to index.html.
    location / {
        root /var/www/html;
        index index.html;
        try_files $uri $uri/ /index.html;
    }
}