2019-05-07 21:23:35 +02:00
|
|
|
#jinja2: lstrip_blocks: "True"
|
2019-08-07 11:53:53 +02:00
|
|
|
|
2022-07-18 11:28:39 +02:00
|
|
|
{% set generic_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'generic_worker') | list %}
|
2022-09-15 06:05:25 +02:00
|
|
|
{% set stream_writer_typing_stream_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'typing') | list %}
|
|
|
|
{% set stream_writer_to_device_stream_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'to_device') | list %}
|
|
|
|
{% set stream_writer_account_data_stream_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'account_data') | list %}
|
|
|
|
{% set stream_writer_receipts_stream_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'receipts') | list %}
|
|
|
|
{% set stream_writer_presence_stream_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'stream_writer') | selectattr('stream_writer_stream', 'equalto', 'presence') | list %}
|
2022-07-18 11:28:39 +02:00
|
|
|
{% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'media_repository') | list %}
|
|
|
|
{% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'user_dir') | list %}
|
2022-09-15 06:05:25 +02:00
|
|
|
|
|
|
|
{% macro render_worker_upstream(name, workers, matrix_nginx_proxy_enabled) %}
|
|
|
|
{% if workers | length > 0 %}
|
|
|
|
upstream {{ name }} {
|
|
|
|
{% for worker in workers %}
|
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
|
|
|
server "{{ worker.name }}:{{ worker.port }}";
|
|
|
|
{% else %}
|
|
|
|
server "127.0.0.1:{{ worker.port }}";
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
|
|
|
|
|
|
|
{% macro render_locations_to_upstream(locations, upstream_name) %}
|
|
|
|
{% for location in locations %}
|
|
|
|
location ~ {{ location }} {
|
|
|
|
proxy_pass http://{{ upstream_name }}$request_uri;
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
{% endmacro %}
|
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
{% if matrix_nginx_proxy_synapse_workers_enabled %}
|
2022-04-21 09:31:26 +02:00
|
|
|
{% if matrix_nginx_proxy_synapse_cache_enabled %}
|
|
|
|
proxy_cache_path {{ matrix_nginx_proxy_synapse_cache_path }} levels=1:2 keys_zone={{ matrix_nginx_proxy_synapse_cache_keys_zone_name }}:{{ matrix_nginx_proxy_synapse_cache_keys_zone_size }} inactive={{ matrix_nginx_proxy_synapse_cache_inactive_time }} max_size={{ matrix_nginx_proxy_synapse_cache_max_size_mb }}m;
|
|
|
|
{% endif %}
|
2021-01-25 09:21:17 +02:00
|
|
|
# Round Robin "upstream" pools for workers
|
2017-07-31 22:07:30 +02:00
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if generic_workers |length > 0 %}
|
|
|
|
upstream generic_workers_upstream {
|
2021-01-25 09:21:17 +02:00
|
|
|
# ensures that requests from the same client will always be passed
|
|
|
|
# to the same server (except when this server is unavailable)
|
2021-04-24 10:52:45 +02:00
|
|
|
hash $http_x_forwarded_for;
|
2018-08-17 07:00:38 +02:00
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
{% for worker in generic_workers %}
|
2021-02-19 11:36:48 +02:00
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
2022-09-15 06:05:25 +02:00
|
|
|
server "{{ worker.name }}:{{ worker.port }}";
|
2021-02-19 11:36:48 +02:00
|
|
|
{% else %}
|
|
|
|
server "127.0.0.1:{{ worker.port }}";
|
|
|
|
{% endif %}
|
2021-01-25 09:21:17 +02:00
|
|
|
{% endfor %}
|
2018-09-17 09:51:46 +02:00
|
|
|
}
|
2019-08-07 11:53:53 +02:00
|
|
|
{% endif %}
|
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{{ render_worker_upstream('stream_writer_typing_stream_workers_upstream', stream_writer_typing_stream_workers, matrix_nginx_proxy_enabled) }}
|
|
|
|
{{ render_worker_upstream('stream_writer_to_device_stream_workers_upstream', stream_writer_to_device_stream_workers, matrix_nginx_proxy_enabled) }}
|
|
|
|
{{ render_worker_upstream('stream_writer_account_data_stream_workers_upstream', stream_writer_account_data_stream_workers, matrix_nginx_proxy_enabled) }}
|
|
|
|
{{ render_worker_upstream('stream_writer_receipts_stream_workers_upstream', stream_writer_receipts_stream_workers, matrix_nginx_proxy_enabled) }}
|
|
|
|
{{ render_worker_upstream('stream_writer_presence_stream_workers_upstream', stream_writer_presence_stream_workers, matrix_nginx_proxy_enabled) }}
|
2018-08-15 09:23:22 +02:00
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{{ render_worker_upstream('media_repository_workers_upstream', media_repository_workers, matrix_nginx_proxy_enabled) }}
|
|
|
|
|
|
|
|
{{ render_worker_upstream('user_dir_workers_upstream', user_dir_workers, matrix_nginx_proxy_enabled) }}
|
2021-01-25 09:21:17 +02:00
|
|
|
{% endif %}
|
2019-01-17 15:55:23 +02:00
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
server {
|
|
|
|
listen 12080;
|
2021-11-05 15:31:10 +02:00
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
|
|
|
server_name {{ matrix_nginx_proxy_proxy_synapse_hostname }};
|
|
|
|
{% endif %}
|
2019-05-08 20:49:51 +02:00
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
server_tokens off;
|
|
|
|
root /dev/null;
|
|
|
|
|
|
|
|
gzip on;
|
|
|
|
gzip_types text/plain application/json;
|
2019-05-08 20:49:51 +02:00
|
|
|
|
2020-08-28 13:53:39 +02:00
|
|
|
{% if matrix_nginx_proxy_synapse_workers_enabled %}
|
2020-12-01 22:55:07 +02:00
|
|
|
{# Workers redirects BEGIN #}
|
2020-08-28 13:53:39 +02:00
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if generic_workers | length > 0 %}
|
2022-09-15 09:46:17 +02:00
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#synapseappgeneric_worker
|
2022-09-15 06:05:25 +02:00
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_generic_worker_client_server_locations, 'generic_workers_upstream') }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if stream_writer_typing_stream_workers | length > 0 %}
|
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#the-typing-stream
|
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_stream_writer_typing_stream_worker_client_server_locations, 'stream_writer_typing_stream_workers_upstream') }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if stream_writer_to_device_stream_workers | length > 0 %}
|
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#the-to_device-stream
|
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_stream_writer_to_device_stream_worker_client_server_locations, 'stream_writer_to_device_stream_workers_upstream') }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if stream_writer_account_data_stream_workers | length > 0 %}
|
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#the-account_data-stream
|
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_stream_writer_account_data_stream_worker_client_server_locations, 'stream_writer_account_data_stream_workers_upstream') }}
|
2020-08-28 13:53:39 +02:00
|
|
|
{% endif %}
|
2020-04-11 03:08:59 +02:00
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if stream_writer_receipts_stream_workers | length > 0 %}
|
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#the-receipts-stream
|
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_stream_writer_receipts_stream_worker_client_server_locations, 'stream_writer_receipts_stream_workers_upstream') }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if stream_writer_presence_stream_workers | length > 0 %}
|
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#the-presence-stream
|
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_stream_writer_presence_stream_worker_client_server_locations, 'stream_writer_presence_stream_workers_upstream') }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if media_repository_workers | length > 0 %}
|
2022-09-15 09:46:17 +02:00
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository
|
2020-08-28 13:53:39 +02:00
|
|
|
{% for location in matrix_nginx_proxy_synapse_media_repository_locations %}
|
|
|
|
location ~ {{ location }} {
|
2022-09-15 06:05:25 +02:00
|
|
|
proxy_pass http://media_repository_workers_upstream$request_uri;
|
2020-08-28 13:53:39 +02:00
|
|
|
proxy_set_header Host $host;
|
2020-11-10 22:43:33 +02:00
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
|
|
|
|
proxy_max_temp_file_size 0;
|
2022-04-21 09:31:26 +02:00
|
|
|
|
|
|
|
{% if matrix_nginx_proxy_synapse_cache_enabled %}
|
|
|
|
proxy_buffering on;
|
|
|
|
proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }};
|
|
|
|
proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }};
|
|
|
|
proxy_force_ranges on;
|
|
|
|
add_header X-Cache-Status $upstream_cache_status;
|
|
|
|
{% endif %}
|
2020-08-28 13:53:39 +02:00
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2020-04-11 03:08:59 +02:00
|
|
|
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if user_dir_workers | length > 0 %}
|
2022-09-15 09:00:57 +02:00
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#updating-the-user-directory
|
|
|
|
# If matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled is set, requests may not reach here,
|
|
|
|
# but could be captured early on (see `matrix-domain.conf.j2`) and forwarded elsewhere (to an identity server, etc.).
|
2022-09-15 06:05:25 +02:00
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_user_dir_locations, 'user_dir_workers_upstream') }}
|
2020-08-28 13:53:39 +02:00
|
|
|
{% endif %}
|
2020-12-01 22:55:07 +02:00
|
|
|
{# Workers redirects END #}
|
2020-04-11 03:08:59 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
{% for configuration_block in matrix_nginx_proxy_proxy_synapse_additional_server_configuration_blocks %}
|
2019-01-17 13:32:46 +02:00
|
|
|
{{- configuration_block }}
|
|
|
|
{% endfor %}
|
2018-10-21 23:20:37 +02:00
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
{# Everything else just goes to the API server ##}
|
|
|
|
location / {
|
2019-05-29 07:32:06 +02:00
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
|
|
|
{# Use the embedded DNS resolver in Docker containers to discover the service #}
|
2022-10-30 00:55:36 +02:00
|
|
|
resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
|
2021-01-25 09:21:17 +02:00
|
|
|
set $backend "{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_with_container }}";
|
2019-05-29 07:32:06 +02:00
|
|
|
proxy_pass http://$backend;
|
|
|
|
{% else %}
|
|
|
|
{# Generic configuration for use outside of our container setup #}
|
2021-01-25 09:21:17 +02:00
|
|
|
proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container }};
|
2019-05-29 07:32:06 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
|
|
|
|
proxy_max_temp_file_size 0;
|
|
|
|
}
|
2019-12-06 11:53:09 +02:00
|
|
|
}
|
|
|
|
|
2021-01-25 09:21:17 +02:00
|
|
|
{% if matrix_nginx_proxy_proxy_synapse_federation_api_enabled %}
|
2019-12-06 11:53:09 +02:00
|
|
|
server {
|
2021-01-25 09:21:17 +02:00
|
|
|
listen 12088;
|
2021-11-05 15:31:10 +02:00
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
|
|
|
server_name {{ matrix_nginx_proxy_proxy_synapse_hostname }};
|
|
|
|
{% endif %}
|
2019-12-06 11:53:09 +02:00
|
|
|
|
|
|
|
server_tokens off;
|
|
|
|
|
|
|
|
root /dev/null;
|
|
|
|
|
|
|
|
gzip on;
|
|
|
|
gzip_types text/plain application/json;
|
|
|
|
|
2020-08-28 13:53:39 +02:00
|
|
|
{% if matrix_nginx_proxy_synapse_workers_enabled %}
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if generic_workers | length > 0 %}
|
2022-09-15 09:46:17 +02:00
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#synapseappgeneric_worker
|
2022-09-15 06:05:25 +02:00
|
|
|
{{ render_locations_to_upstream(matrix_nginx_proxy_synapse_generic_worker_federation_locations, 'generic_workers_upstream') }}
|
2020-08-28 13:53:39 +02:00
|
|
|
{% endif %}
|
2022-09-15 06:05:25 +02:00
|
|
|
{% if media_repository_workers | length > 0 %}
|
2022-09-15 09:46:17 +02:00
|
|
|
# https://matrix-org.github.io/synapse/latest/workers.html#synapseappmedia_repository
|
2020-11-10 21:35:39 +02:00
|
|
|
{% for location in matrix_nginx_proxy_synapse_media_repository_locations %}
|
|
|
|
location ~ {{ location }} {
|
2022-09-15 06:05:25 +02:00
|
|
|
proxy_pass http://media_repository_workers_upstream$request_uri;
|
2020-11-10 21:35:39 +02:00
|
|
|
proxy_set_header Host $host;
|
2020-11-10 22:43:33 +02:00
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
|
|
|
|
proxy_max_temp_file_size 0;
|
2022-04-21 09:31:26 +02:00
|
|
|
|
|
|
|
{% if matrix_nginx_proxy_synapse_cache_enabled %}
|
|
|
|
proxy_buffering on;
|
|
|
|
proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }};
|
|
|
|
proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }};
|
|
|
|
proxy_force_ranges on;
|
|
|
|
add_header X-Cache-Status $upstream_cache_status;
|
|
|
|
{% endif %}
|
2020-11-10 21:35:39 +02:00
|
|
|
}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2020-08-27 15:25:32 +02:00
|
|
|
{% endif %}
|
2020-04-11 03:08:59 +02:00
|
|
|
|
2019-02-05 11:07:08 +02:00
|
|
|
location / {
|
|
|
|
{% if matrix_nginx_proxy_enabled %}
|
|
|
|
{# Use the embedded DNS resolver in Docker containers to discover the service #}
|
2022-10-30 00:55:36 +02:00
|
|
|
resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
|
2021-01-25 09:21:17 +02:00
|
|
|
set $backend "{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container }}";
|
2019-02-05 11:07:08 +02:00
|
|
|
proxy_pass http://$backend;
|
|
|
|
{% else %}
|
|
|
|
{# Generic configuration for use outside of our container setup #}
|
2021-01-25 09:21:17 +02:00
|
|
|
proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container }};
|
2019-02-05 11:07:08 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
|
|
|
client_body_buffer_size 25M;
|
|
|
|
client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
|
|
|
|
proxy_max_temp_file_size 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{% endif %}
|