server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # Proxy /api and all subpaths to backend service (back container on port 8080) location /api/ { proxy_pass http://back:8080/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_http_version 1.1; proxy_set_header Connection ""; } # Also handle /api without trailing slash location = /api { proxy_pass http://back:8080/api; } # SPA fallback for client-side routing location / { try_files $uri $uri/ /index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }