server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # Resolve the backend hostname at request time (via Docker's embedded DNS) # instead of once at startup, so a recreated backend container is picked # up without needing to restart/reload this nginx. resolver 127.0.0.11 valid=30s; location /api/ { set $backend_upstream presencia-backend; # $request_uri (the raw, un-normalized original URI) must be appended # explicitly: when the proxy_pass target is built from a variable, # nginx does NOT replace the matched location prefix with the rest of # the request URI like it does for a static proxy_pass value — it # would otherwise always forward the literal "/api/" with nothing # appended, regardless of the actual path requested. proxy_pass http://$backend_upstream:4790$request_uri; proxy_http_version 1.1; 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; } location / { try_files $uri $uri/ /index.html; } }