Skip to content

Commit 9dcbb78

Browse files
committed
chore: nginx runtime proxy + startup script to forward /api to backend; support SSE; ignore tmp/
1 parent 4fcc956 commit 9dcbb78

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

nginx.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ events {
55
http {
66
include /etc/nginx/mime.types;
77
default_type application/octet-stream;
8+
# Allow additional runtime-injected virtual host fragments (created by /startup.sh)
9+
include /etc/nginx/conf.d/*.conf;
810

911
server {
1012
listen 80;

startup.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,36 @@ fi
7979

8080
echo "✅ Runtime configuration setup complete!"
8181

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)"
84+
cat > /etc/nginx/conf.d/api-proxy.conf << EOF
85+
# 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+
}
108+
}
109+
EOF
110+
echo "✅ Wrote /etc/nginx/conf.d/api-proxy.conf"
111+
82112
# Start nginx
83113
echo "🌐 Starting nginx..."
84114
exec nginx -g "daemon off;"

0 commit comments

Comments
 (0)