-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
108 lines (92 loc) · 5.28 KB
/
Copy pathnginx.conf
File metadata and controls
108 lines (92 loc) · 5.28 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Nginx Configuration - Frontend Proxy & Static Asset Server
#
# This configuration serves the React frontend and proxies API requests to the Go backend.
# Optimized for the Article-Chat hybrid architecture with special handling for:
# - Single Page Application (SPA) routing
# - API request proxying to Go backend service
# - Server-Sent Events (SSE) for streaming chat responses
# - Static asset optimization with proper MIME types
#
# KEY FEATURES:
# - Client-Side Routing: All non-API routes fallback to index.html for React Router
# - API Proxy: Seamless forwarding of /api/* requests to Go backend container
# - SSE Support: Optimized configuration for streaming chat responses
# - Production Optimization: Proper headers, timeouts, and buffering configuration
#
# CONTAINER COMMUNICATION:
# - backend-go: Resolves to Go backend container via Docker DNS
# - Requests flow: Browser → nginx (port 3000) → Go backend (port 8080)
events {
worker_connections 1024; # Maximum concurrent connections per worker
}
http {
include /etc/nginx/mime.types; # Load MIME type mappings for static assets
default_type application/octet-stream; # Default MIME type for unknown files
server {
listen 3000; # Frontend service port
server_name localhost; # Server name for this configuration
root /usr/share/nginx/html; # React build output directory
index index.html; # Default file for directory requests
# ====================================================================
# REACT SPA ROUTING - Client-Side Navigation Support
# ====================================================================
location / {
try_files $uri $uri/ /index.html; # Fallback to index.html for client-side routing
# This enables React Router to handle all frontend navigation
# If a file doesn't exist, serve index.html to let React Router take over
}
# ====================================================================
# API PROXY - Go Backend Gateway Communication
# ====================================================================
location /api/ {
proxy_pass http://backend-go:8080; # Forward to Go backend container
# Standard proxy headers for proper request forwarding
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;
# Timeout settings optimized for RAG operations
# RAG service can take 5-8 seconds for complex queries
proxy_connect_timeout 60s; # Time to establish connection to backend
proxy_send_timeout 60s; # Time to send request to backend
proxy_read_timeout 120s; # Time to read response from backend
# Buffer settings for streaming and large responses
proxy_buffering off; # Disable buffering for real-time responses
proxy_cache_bypass $http_upgrade; # Bypass cache for dynamic content
}
# ====================================================================
# SERVER-SENT EVENTS (SSE) - Streaming Chat Response Support
# ====================================================================
location /api/chat {
proxy_pass http://backend-go:8080;
proxy_http_version 1.1; # Required for persistent connections
# Standard proxy headers
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;
# SSE-specific configuration for streaming responses
proxy_buffering off; # Critical: Disable buffering for streaming
proxy_cache off; # Disable caching for real-time data
proxy_read_timeout 300s; # Extended timeout for long AI responses
proxy_send_timeout 300s; # Extended send timeout
# SSE headers for proper browser handling
proxy_set_header Cache-Control "no-cache"; # Prevent caching of stream data
proxy_set_header Connection ""; # Clean connection handling
}
# ====================================================================
# WEBSOCKET FALLBACK - Future Real-time Communication Support
# ====================================================================
location /ws/ {
proxy_pass http://backend-go:8080;
proxy_http_version 1.1;
# WebSocket upgrade headers
proxy_set_header Upgrade $http_upgrade; # Enable WebSocket upgrade
proxy_set_header Connection "upgrade"; # Connection upgrade header
# Standard proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}