1+ # This is a new file: src/server/nginx.conf
2+
3+ upstream backend_app {
4+ # This points to your FastAPI/Uvicorn server running on localhost inside the container.
5+ server 127.0.0.1:5000 ;
6+ }
7+
8+ server {
9+ # Nginx will listen on port 80 inside the container.
10+ # GCP's Load Balancer will handle HTTPS termination and forward traffic to this port.
11+ listen 80 ;
12+ server_name _; # Catch all domains forwarded by GCP
13+
14+ # Location block for your chat stream
15+ location /api/chat/message {
16+ proxy_pass http ://backend_app;
17+
18+ # Streaming-Specific Settings
19+ proxy_set_header Host $host ;
20+ proxy_set_header X-Real-IP $remote_addr ;
21+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
22+ proxy_set_header X-Forwarded-Proto $scheme ;
23+
24+ # Critical: Disable buffering for this endpoint
25+ proxy_buffering off;
26+
27+ # Increase timeouts for long-lived stream
28+ proxy_read_timeout 86400s ;
29+ proxy_send_timeout 86400s ;
30+
31+ # Required for keep-alive connections
32+ proxy_http_version 1.1;
33+ proxy_set_header Connection '' ;
34+
35+ # Add CORS headers if needed, though your app likely handles this.
36+ add_header 'Access-Control-Allow-Origin' '*' always;
37+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
38+ add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
39+ if ( $request_method = 'OPTIONS' ) {
40+ add_header 'Access-Control-Max-Age' 1728000 ;
41+ add_header 'Content-Type' 'text/plain; charset=utf-8' ;
42+ add_header 'Content-Length' 0;
43+ return 204 ;
44+ }
45+ }
46+
47+ # General location block for all other API requests
48+ location / {
49+ proxy_pass http ://backend_app;
50+ proxy_set_header Host $host ;
51+ proxy_set_header X-Real-IP $remote_addr ;
52+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
53+ proxy_set_header X-Forwarded-Proto $scheme ;
54+ }
55+ }
0 commit comments