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.
 
 

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