|
79 | 79 |
|
80 | 80 | echo "✅ Runtime configuration setup complete!" |
81 | 81 |
|
82 | | -# Create an api-proxy config so the container can forward /api requests to the real backend |
83 | | -echo "📡 Creating API proxy config (/etc/nginx/conf.d/api-proxy.conf)" |
| 82 | +# Create an api-proxy location fragment so the container can forward /api requests |
| 83 | +# to the real backend. This writes only a `location` block so the fragment can be |
| 84 | +# included inside the main server block defined in nginx.conf. |
| 85 | +echo "📡 Creating API proxy location fragment (/etc/nginx/conf.d/api-proxy.conf)" |
84 | 86 | cat > /etc/nginx/conf.d/api-proxy.conf << EOF |
85 | 87 | # Dynamically generated by startup.sh - proxies /api/* to the backend provided by VITE_BACKEND_BASE_URL |
86 | | -proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=one:10m max_size=100m inactive=60m; |
87 | | -upstream backend_api { |
88 | | - server ${VITE_BACKEND_BASE_URL}; |
89 | | -} |
90 | | -
|
91 | | -server { |
92 | | - listen 127.0.0.1:8080; # internal server used for proxy fragment only |
93 | | -
|
94 | | - # Proxy any /api requests to the configured backend. This preserves SSE |
95 | | - location /api/ { |
96 | | - proxy_pass ${VITE_BACKEND_BASE_URL}/api/; |
97 | | - proxy_set_header Host $host; |
98 | | - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
99 | | - proxy_set_header X-Forwarded-Proto $scheme; |
100 | | - proxy_http_version 1.1; |
101 | | - proxy_set_header Connection ''; |
102 | | - proxy_buffering off; # important for SSE |
103 | | - chunked_transfer_encoding off; |
104 | | - proxy_cache_bypass $http_upgrade; |
105 | | - proxy_read_timeout 3600s; |
106 | | - proxy_send_timeout 3600s; |
107 | | - } |
| 88 | +location /api/ { |
| 89 | + # Forward to the backend base url. Note: using a full URL here lets nginx |
| 90 | + # perform an external proxy pass to the backend host configured at runtime. |
| 91 | + proxy_pass ${VITE_BACKEND_BASE_URL}/api/; |
| 92 | + proxy_set_header Host $host; |
| 93 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 94 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 95 | + proxy_http_version 1.1; |
| 96 | + proxy_set_header Connection ''; |
| 97 | + proxy_buffering off; # important for SSE |
| 98 | + chunked_transfer_encoding off; |
| 99 | + proxy_cache_bypass $http_upgrade; |
| 100 | + proxy_read_timeout 3600s; |
| 101 | + proxy_send_timeout 3600s; |
108 | 102 | } |
109 | 103 | EOF |
110 | 104 | echo "✅ Wrote /etc/nginx/conf.d/api-proxy.conf" |
|
0 commit comments