From 9f86aaf540b724e2db088d0bcfbfa039d58483df Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Mon, 23 Feb 2026 22:27:52 +0000 Subject: [PATCH] add K8s nginx config and parameterize Dockerfile.dashboard Create nginx-k8s.conf that proxies to localhost:8000 instead of api-gateway:8000 for K8s pods where both containers share a network namespace. Update Dockerfile.dashboard to accept a NGINX_CONF build arg (defaults to docker/nginx.conf for docker-compose compatibility). --- docker/Dockerfile.dashboard | 5 ++- docker/nginx-k8s.conf | 77 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 docker/nginx-k8s.conf diff --git a/docker/Dockerfile.dashboard b/docker/Dockerfile.dashboard index 0ccb223..e0deb45 100644 --- a/docker/Dockerfile.dashboard +++ b/docker/Dockerfile.dashboard @@ -23,8 +23,9 @@ FROM nginx:alpine # Remove default nginx site RUN rm /etc/nginx/conf.d/default.conf -# Copy custom nginx config -COPY docker/nginx.conf /etc/nginx/conf.d/default.conf +# Copy custom nginx config (override NGINX_CONF for K8s builds) +ARG NGINX_CONF=docker/nginx.conf +COPY ${NGINX_CONF} /etc/nginx/conf.d/default.conf # Copy built assets from the builder stage COPY --from=builder /app/dist /usr/share/nginx/html diff --git a/docker/nginx-k8s.conf b/docker/nginx-k8s.conf new file mode 100644 index 0000000..899c720 --- /dev/null +++ b/docker/nginx-k8s.conf @@ -0,0 +1,77 @@ +# nginx configuration for the trading-bot dashboard (Kubernetes variant). +# Serves the React SPA and proxies API / WebSocket requests to the api-gateway. +# In K8s both containers share a pod, so the upstream is localhost instead of +# the Docker Compose service hostname "api-gateway". + +server { + listen 80; + server_name _; + + root /usr/share/nginx/html; + index index.html; + + # --------------------------------------------------------------------------- + # SPA: serve index.html for any path not matching a static file + # --------------------------------------------------------------------------- + location / { + try_files $uri $uri/ /index.html; + } + + # --------------------------------------------------------------------------- + # Proxy /api/auth/* to the api-gateway /auth/* routes + # (Dashboard client uses baseURL=/api, so auth calls arrive as /api/auth/*) + # --------------------------------------------------------------------------- + location /api/auth/ { + proxy_pass http://localhost:8000/auth/; + 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 /api/* to the api-gateway service + # --------------------------------------------------------------------------- + location /api/ { + proxy_pass http://localhost:8000/api/; + 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 /auth/* to the api-gateway service + # --------------------------------------------------------------------------- + location /auth/ { + proxy_pass http://localhost:8000; + 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 /health to the api-gateway service + # --------------------------------------------------------------------------- + location /health { + proxy_pass http://localhost:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + # --------------------------------------------------------------------------- + # WebSocket upgrade for /ws + # --------------------------------------------------------------------------- + location /ws { + proxy_pass http://localhost:8000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + 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_read_timeout 86400; + } +}