From f2b69feb2942617c770b4d0e5cf2b4fa2acb9788 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Thu, 16 Jan 2025 10:13:27 +0200 Subject: [PATCH] Make catch-all `federation-reader` nginx `location` blocks have less priority than others Potentially fixes https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/3918 --- ...ix-synapse-reverse-proxy-companion.conf.j2 | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 f32fe1e27..d278267dc 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 @@ -269,14 +269,12 @@ server { # https://tcpipuk.github.io/synapse/deployment/workers.html {{ render_locations_to_upstream(matrix_synapse_reverse_proxy_companion_synapse_room_worker_federation_locations, 'room_workers_upstream') }} {% endif %} - {% if federation_reader_workers | length > 0 %} - # https://tcpipuk.github.io/synapse/deployment/workers.html - {{ render_locations_to_upstream(matrix_synapse_reverse_proxy_companion_synapse_federation_reader_federation_locations, 'federation_reader_workers_upstream') }} - {% endif %} + {% if generic_workers | length > 0 %} # https://matrix-org.github.io/synapse/latest/workers.html#synapseappgeneric_worker {{ render_locations_to_upstream(matrix_synapse_reverse_proxy_companion_synapse_generic_worker_federation_locations, 'generic_workers_upstream') }} {% endif %} + {% if media_repository_workers | length > 0 %} # https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository {% for location in matrix_synapse_reverse_proxy_companion_synapse_media_repository_locations %} @@ -298,6 +296,20 @@ server { } {% endfor %} {% endif %} + + {# + This is last, because we'd like more-specific requests (e.g. `/_matrix/federation/v1/media/` that may be handled by a media repository worker, if enabled) + to be routed to more specialized workers via their respective `locations` defined earlier (above). + + As https://nginx.org/en/docs/http/ngx_http_core_module.html#location says about location matching: + > .. Then regular expressions are checked, in the order of their appearance in the configuration file. + + See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/3918 + #} + {% if federation_reader_workers | length > 0 %} + # https://tcpipuk.github.io/synapse/deployment/workers.html + {{ render_locations_to_upstream(matrix_synapse_reverse_proxy_companion_synapse_federation_reader_federation_locations, 'federation_reader_workers_upstream') }} + {% endif %} {% endif %} {% for configuration_block in matrix_synapse_reverse_proxy_companion_synapse_federation_api_additional_server_configuration_blocks %}