From 8ae600f2e58e9a108642d38030c0126e4cdf99c3 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Wed, 6 Nov 2019 04:03:05 -0800 Subject: [PATCH] nginx: Prevent nginx from caching dns results Otherwise if the containers get restarted and change ip, nginx hits the wrong ip. We do this via a hack where we make all references indirect through a variable. Since nginx only resolves this at request time, it always does a dns request. --- nginx/generate-config | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nginx/generate-config b/nginx/generate-config index 215389f..4336ab2 100755 --- a/nginx/generate-config +++ b/nginx/generate-config @@ -9,7 +9,8 @@ generate_location() { # generate_location PATH URL - echo -e "\t\tlocation $1 { proxy_pass $2; }" + # We indirect via a variable to prevent nginx from caching dns forever + echo -e "\t\tlocation $1 { set \$name \"$2\"; proxy_pass \$name; }" } LOCATIONS=$( @@ -37,6 +38,7 @@ events { http { include /etc/nginx/mime.types; + resolver 127.0.0.11 valid=10s; server { listen 80; gzip on;