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).
This commit is contained in:
Viktor Barzin 2026-02-23 22:27:52 +00:00
parent ed3bf57566
commit 9f86aaf540
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 80 additions and 2 deletions

View file

@ -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

77
docker/nginx-k8s.conf Normal file
View file

@ -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;
}
}