From 1c68fd0d9b44aae71abd47a75f89deaaaea84778 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Wed, 5 Mar 2025 21:24:43 +0200 Subject: [PATCH] Make matrix-synapse-reverse-proxy-companion not report "502 Bad Gateway" when Synapse workers restart Since nginx 1.27.3, we can make use of the `resolve` parameter for an `upstream`'s `server`, to allow DNS resolution to happen continuously at runtime, not just once during startup. Previously, this was not possible to do in an `upstream` block without an nginx-plus subscription. Outside of an `upstream` block, we've used and still use `set $backend ..` workarounds to get DNS resolution at runtime, but now we can do it in `upstream` as well. --- .../matrix-synapse-reverse-proxy-companion.conf.j2 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/roles/custom/matrix-synapse-reverse-proxy-companion/templates/nginx/conf.d/matrix-synapse-reverse-proxy-companion.conf.j2 b/roles/custom/matrix-synapse-reverse-proxy-companion/templates/nginx/conf.d/matrix-synapse-reverse-proxy-companion.conf.j2 index 57dee1d9b..46dbb010e 100644 --- a/roles/custom/matrix-synapse-reverse-proxy-companion/templates/nginx/conf.d/matrix-synapse-reverse-proxy-companion.conf.j2 +++ b/roles/custom/matrix-synapse-reverse-proxy-companion/templates/nginx/conf.d/matrix-synapse-reverse-proxy-companion.conf.j2 @@ -16,10 +16,18 @@ {% macro render_worker_upstream(name, workers, load_balance) %} {% if workers | length > 0 %} upstream {{ name }} { + {# + We need to use a zone so that the upstream is stored in shared memory, + otherwise we can't use `resolve` below, as reported by nginx: + > resolving names at run time requires upstream ".." in ... to be in shared memory + #} + zone {{ name }} 64k; + {{ load_balance }} keepalive {{ ((workers | length) * 2) | string }}; + resolver {{ matrix_synapse_reverse_proxy_companion_http_level_resolver }} valid=5s; {% for worker in workers %} - server "{{ worker.name }}:{{ worker.port }}"; + server "{{ worker.name }}:{{ worker.port }}" resolve; {% endfor %} } {% endif %}