Fix Nginx backend proxy resolution and prevent startup failures
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.
This commit is contained in:
+6
-1
@@ -7,7 +7,12 @@ server {
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8080/;
|
||||
# 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;
|
||||
|
||||
Reference in New Issue
Block a user