Skip to content

Commit c59b5cd

Browse files
authored
fix: delay upstream DNS resolution to prevent startup failures (#2718)
Use nginx variable pattern (set $upstream + proxy_pass https://$upstream) to defer DNS resolution until first request instead of at config parse time. This fixes the occasional 'host not found in upstream' error in CI when nginx container starts before Docker DNS is fully available. Fixes #2712
1 parent ee49a2b commit c59b5cd

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

travis/libcdb_nginx_cache.conf

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ http {
1010
access_log /dev/stdout cache_st;
1111
# Use Docker's embedded DNS server to resolve hostnames at runtime
1212
# instead of at startup.
13-
resolver 127.0.0.11 8.8.8.8 ipv6=off;
13+
resolver 127.0.0.11 8.8.8.8 ipv6=off valid=30s;
14+
# Set default resolver for all upstreams to avoid startup-time DNS resolution
15+
# This is a workaround for the occasional 'host not found in upstream' error
16+
# in Docker environments where DNS may not be immediately available.
1417

1518
server {
1619
listen 3000;
1720
proxy_cache my_cache;
1821

1922
location / {
20-
proxy_set_header Host debuginfod.elfutils.org;
23+
set $upstream_host "debuginfod.elfutils.org";
24+
proxy_set_header Host $upstream_host;
2125
proxy_ssl_server_name on;
2226
proxy_cache_revalidate on;
2327
proxy_cache_key $scheme://$host$uri$is_args$query_string;
2428
proxy_cache_valid 200 404 12w;
2529
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
26-
proxy_pass https://debuginfod.elfutils.org/;
30+
proxy_pass https://$upstream_host/;
2731
}
2832
}
2933

@@ -32,14 +36,15 @@ http {
3236
proxy_cache my_cache;
3337

3438
location / {
35-
proxy_set_header Host libc.rip;
39+
set $upstream_host "libc.rip";
40+
proxy_set_header Host $upstream_host;
3641
proxy_ssl_server_name on;
3742
proxy_cache_methods GET HEAD POST;
3843
proxy_cache_revalidate on;
3944
proxy_cache_key $scheme://$host$uri$is_args$query_string$request_body;
4045
proxy_cache_valid 200 404 12w;
4146
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
42-
proxy_pass https://libc.rip/;
47+
proxy_pass https://$upstream_host/;
4348
}
4449
}
4550

@@ -48,12 +53,13 @@ http {
4853
proxy_cache my_cache;
4954

5055
location / {
51-
proxy_set_header Host archive.ubuntu.com;
56+
set $upstream_host "archive.ubuntu.com";
57+
proxy_set_header Host $upstream_host;
5258
proxy_cache_revalidate on;
5359
proxy_cache_key $scheme://$host$uri$is_args$query_string;
5460
proxy_cache_valid 200 404 12w;
5561
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
56-
proxy_pass http://archive.ubuntu.com/;
62+
proxy_pass http://$upstream_host/;
5763
}
5864
}
5965

@@ -62,14 +68,15 @@ http {
6268
proxy_cache my_cache;
6369

6470
location / {
65-
proxy_set_header Host gitlab.com;
71+
set $upstream_host "gitlab.com";
72+
proxy_set_header Host $upstream_host;
6673
proxy_ssl_server_name on;
6774
proxy_cache_revalidate on;
6875
proxy_cache_key $scheme://$host$uri$is_args$query_string;
6976
proxy_cache_valid 200 404 12w;
7077
proxy_ignore_headers Cache-Control Set-Cookie;
7178
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
72-
proxy_pass https://gitlab.com/;
79+
proxy_pass https://$upstream_host/;
7380
}
7481
}
7582

@@ -78,13 +85,15 @@ http {
7885
proxy_cache my_cache;
7986

8087
location / {
81-
proxy_set_header Host debuginfod.ubuntu.com;
88+
set $upstream_host "debuginfod.ubuntu.com";
89+
proxy_set_header Host $upstream_host;
8290
proxy_ssl_server_name on;
8391
proxy_cache_revalidate on;
8492
proxy_cache_key $scheme://$host$uri$is_args$query_string;
8593
proxy_cache_valid 200 404 12w;
8694
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
87-
proxy_pass https://debuginfod.ubuntu.com/;
95+
proxy_pass https://$upstream_host/;
8896
}
8997
}
9098
}
99+

0 commit comments

Comments
 (0)