Added dynamic DNS resolution for the backend service to prevent Nginx from failing when the backend container is not yet available during startup. Implemented Docker's internal resolver with a 10-second validity period and moved the backend URL to a variable for runtime resolution. Replaced direct proxy_pass with rewrite rule for proper path handling.
26 lines
710 B
Nginx Configuration File
26 lines
710 B
Nginx Configuration File
server {
|
|
listen 80;
|
|
|
|
location / {
|
|
root /usr/share/nginx/html;
|
|
try_files $uri /index.html;
|
|
}
|
|
|
|
location /api/ {
|
|
# Resolve the Docker service at request time. This prevents Nginx from
|
|
# exiting when the Docker DNS entry is not ready during container startup.
|
|
resolver 127.0.0.11 ipv6=off valid=10s;
|
|
set $backend_upstream http://backend:8080;
|
|
rewrite ^/api/(.*)$ /$1 break;
|
|
proxy_pass $backend_upstream;
|
|
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;
|
|
|
|
proxy_cookie_path / "/; SameSite=Lax";
|
|
}
|
|
}
|