Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

204 lines
7.2 KiB

  1. #jinja2: lstrip_blocks: "True"
  2. {% set generic_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'generic_worker') | list %}
  3. {% set media_repository_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'media_repository') | list %}
  4. {% set user_dir_workers = matrix_nginx_proxy_synapse_workers_list | selectattr('type', 'equalto', 'user_dir') | list %}
  5. {% if matrix_nginx_proxy_synapse_workers_enabled %}
  6. {% if matrix_nginx_proxy_synapse_cache_enabled %}
  7. 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;
  8. {% endif %}
  9. # Round Robin "upstream" pools for workers
  10. {% if generic_workers %}
  11. upstream generic_worker_upstream {
  12. # ensures that requests from the same client will always be passed
  13. # to the same server (except when this server is unavailable)
  14. hash $http_x_forwarded_for;
  15. {% for worker in generic_workers %}
  16. {% if matrix_nginx_proxy_enabled %}
  17. server "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.port }}";
  18. {% else %}
  19. server "127.0.0.1:{{ worker.port }}";
  20. {% endif %}
  21. {% endfor %}
  22. }
  23. {% endif %}
  24. {% if media_repository_workers %}
  25. upstream media_repository_upstream {
  26. {% for worker in media_repository_workers %}
  27. {% if matrix_nginx_proxy_enabled %}
  28. server "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.port }}";
  29. {% else %}
  30. server "127.0.0.1:{{ worker.port }}";
  31. {% endif %}
  32. {% endfor %}
  33. }
  34. {% endif %}
  35. {% if user_dir_workers %}
  36. upstream user_dir_upstream {
  37. {% for worker in user_dir_workers %}
  38. {% if matrix_nginx_proxy_enabled %}
  39. server "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.port }}";
  40. {% else %}
  41. server "127.0.0.1:{{ worker.port }}";
  42. {% endif %}
  43. {% endfor %}
  44. }
  45. {% endif %}
  46. {% endif %}
  47. server {
  48. listen 12080;
  49. {% if matrix_nginx_proxy_enabled %}
  50. server_name {{ matrix_nginx_proxy_proxy_synapse_hostname }};
  51. {% endif %}
  52. server_tokens off;
  53. root /dev/null;
  54. gzip on;
  55. gzip_types text/plain application/json;
  56. {% if matrix_nginx_proxy_synapse_workers_enabled %}
  57. {# Workers redirects BEGIN #}
  58. {% if generic_workers %}
  59. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappgeneric_worker
  60. {% for location in matrix_nginx_proxy_synapse_generic_worker_client_server_locations %}
  61. location ~ {{ location }} {
  62. proxy_pass http://generic_worker_upstream$request_uri;
  63. proxy_set_header Host $host;
  64. }
  65. {% endfor %}
  66. {% endif %}
  67. {% if media_repository_workers %}
  68. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappmedia_repository
  69. {% for location in matrix_nginx_proxy_synapse_media_repository_locations %}
  70. location ~ {{ location }} {
  71. proxy_pass http://media_repository_upstream$request_uri;
  72. proxy_set_header Host $host;
  73. client_body_buffer_size 25M;
  74. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  75. proxy_max_temp_file_size 0;
  76. {% if matrix_nginx_proxy_synapse_cache_enabled %}
  77. proxy_buffering on;
  78. proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }};
  79. proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }};
  80. proxy_force_ranges on;
  81. add_header X-Cache-Status $upstream_cache_status;
  82. {% endif %}
  83. }
  84. {% endfor %}
  85. {% endif %}
  86. {% if user_dir_workers %}
  87. # FIXME: obsolete if matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled is set
  88. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappuser_dir
  89. {% for location in matrix_nginx_proxy_synapse_user_dir_locations %}
  90. location ~ {{ location }} {
  91. proxy_pass http://user_dir_upstream$request_uri;
  92. proxy_set_header Host $host;
  93. }
  94. {% endfor %}
  95. {% endif %}
  96. {# Workers redirects END #}
  97. {% endif %}
  98. {% for configuration_block in matrix_nginx_proxy_proxy_synapse_additional_server_configuration_blocks %}
  99. {{- configuration_block }}
  100. {% endfor %}
  101. {# Everything else just goes to the API server ##}
  102. location / {
  103. {% if matrix_nginx_proxy_enabled %}
  104. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  105. resolver 127.0.0.11 valid=5s;
  106. set $backend "{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_with_container }}";
  107. proxy_pass http://$backend;
  108. {% else %}
  109. {# Generic configuration for use outside of our container setup #}
  110. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container }};
  111. {% endif %}
  112. proxy_set_header Host $host;
  113. client_body_buffer_size 25M;
  114. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  115. proxy_max_temp_file_size 0;
  116. }
  117. }
  118. {% if matrix_nginx_proxy_proxy_synapse_federation_api_enabled %}
  119. server {
  120. listen 12088;
  121. {% if matrix_nginx_proxy_enabled %}
  122. server_name {{ matrix_nginx_proxy_proxy_synapse_hostname }};
  123. {% endif %}
  124. server_tokens off;
  125. root /dev/null;
  126. gzip on;
  127. gzip_types text/plain application/json;
  128. {% if matrix_nginx_proxy_synapse_workers_enabled %}
  129. {% if generic_workers %}
  130. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappgeneric_worker
  131. {% for location in matrix_nginx_proxy_synapse_generic_worker_federation_locations %}
  132. location ~ {{ location }} {
  133. proxy_pass http://generic_worker_upstream$request_uri;
  134. proxy_set_header Host $host;
  135. }
  136. {% endfor %}
  137. {% endif %}
  138. {% if media_repository_workers %}
  139. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappmedia_repository
  140. {% for location in matrix_nginx_proxy_synapse_media_repository_locations %}
  141. location ~ {{ location }} {
  142. proxy_pass http://media_repository_upstream$request_uri;
  143. proxy_set_header Host $host;
  144. client_body_buffer_size 25M;
  145. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  146. proxy_max_temp_file_size 0;
  147. {% if matrix_nginx_proxy_synapse_cache_enabled %}
  148. proxy_buffering on;
  149. proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }};
  150. proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }};
  151. proxy_force_ranges on;
  152. add_header X-Cache-Status $upstream_cache_status;
  153. {% endif %}
  154. }
  155. {% endfor %}
  156. {% endif %}
  157. {% endif %}
  158. location / {
  159. {% if matrix_nginx_proxy_enabled %}
  160. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  161. resolver 127.0.0.11 valid=5s;
  162. set $backend "{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container }}";
  163. proxy_pass http://$backend;
  164. {% else %}
  165. {# Generic configuration for use outside of our container setup #}
  166. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container }};
  167. {% endif %}
  168. proxy_set_header Host $host;
  169. client_body_buffer_size 25M;
  170. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  171. proxy_max_temp_file_size 0;
  172. }
  173. }
  174. {% endif %}