Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

273 wiersze
9.9 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. {% if matrix_nginx_proxy_proxy_synapse_metrics %}
  130. location /_synapse/metrics {
  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_metrics_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_metrics_addr_sans_container }};
  139. {% endif %}
  140. proxy_set_header Host $host;
  141. {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %}
  142. auth_basic "protected";
  143. auth_basic_user_file {{ matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_path }};
  144. {% endif %}
  145. }
  146. {% endif %}
  147. {% if matrix_nginx_proxy_enabled and matrix_nginx_proxy_proxy_synapse_metrics %}
  148. {% for worker in matrix_nginx_proxy_proxy_synapse_workers_enabled_list %}
  149. {% if worker.metrics_port != 0 %}
  150. location /_synapse-worker-{{ worker.type }}-{{ worker.instanceId }}/metrics {
  151. resolver 127.0.0.11 valid=5s;
  152. set $backend "matrix-synapse-worker-{{ worker.type }}-{{ worker.instanceId }}:{{ worker.metrics_port }}";
  153. proxy_pass http://$backend/_synapse/metrics;
  154. proxy_set_header Host $host;
  155. {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %}
  156. auth_basic "protected";
  157. auth_basic_user_file {{ matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_path }};
  158. {% endif %}
  159. }
  160. {% endif %}
  161. {% endfor %}
  162. {% endif %}
  163. {# Everything else just goes to the API server ##}
  164. location / {
  165. {% if matrix_nginx_proxy_enabled %}
  166. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  167. resolver 127.0.0.11 valid=5s;
  168. set $backend "{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_with_container }}";
  169. proxy_pass http://$backend;
  170. {% else %}
  171. {# Generic configuration for use outside of our container setup #}
  172. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_client_api_addr_sans_container }};
  173. {% endif %}
  174. proxy_set_header Host $host;
  175. client_body_buffer_size 25M;
  176. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  177. proxy_max_temp_file_size 0;
  178. }
  179. }
  180. {% if matrix_nginx_proxy_proxy_synapse_federation_api_enabled %}
  181. server {
  182. listen 12088;
  183. {% if matrix_nginx_proxy_enabled %}
  184. server_name {{ matrix_nginx_proxy_proxy_synapse_hostname }};
  185. {% endif %}
  186. server_tokens off;
  187. root /dev/null;
  188. gzip on;
  189. gzip_types text/plain application/json;
  190. {% if matrix_nginx_proxy_synapse_workers_enabled %}
  191. {% if generic_workers %}
  192. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappgeneric_worker
  193. {% for location in matrix_nginx_proxy_synapse_generic_worker_federation_locations %}
  194. location ~ {{ location }} {
  195. proxy_pass http://generic_worker_upstream$request_uri;
  196. proxy_set_header Host $host;
  197. }
  198. {% endfor %}
  199. {% endif %}
  200. {% if media_repository_workers %}
  201. # https://github.com/matrix-org/synapse/blob/master/docs/workers.md#synapseappmedia_repository
  202. {% for location in matrix_nginx_proxy_synapse_media_repository_locations %}
  203. location ~ {{ location }} {
  204. proxy_pass http://media_repository_upstream$request_uri;
  205. proxy_set_header Host $host;
  206. client_body_buffer_size 25M;
  207. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  208. proxy_max_temp_file_size 0;
  209. {% if matrix_nginx_proxy_synapse_cache_enabled %}
  210. proxy_buffering on;
  211. proxy_cache {{ matrix_nginx_proxy_synapse_cache_keys_zone_name }};
  212. proxy_cache_valid any {{ matrix_nginx_proxy_synapse_cache_proxy_cache_valid_time }};
  213. proxy_force_ranges on;
  214. add_header X-Cache-Status $upstream_cache_status;
  215. {% endif %}
  216. }
  217. {% endfor %}
  218. {% endif %}
  219. {% endif %}
  220. location / {
  221. {% if matrix_nginx_proxy_enabled %}
  222. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  223. resolver 127.0.0.11 valid=5s;
  224. set $backend "{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_with_container }}";
  225. proxy_pass http://$backend;
  226. {% else %}
  227. {# Generic configuration for use outside of our container setup #}
  228. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_federation_api_addr_sans_container }};
  229. {% endif %}
  230. proxy_set_header Host $host;
  231. client_body_buffer_size 25M;
  232. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  233. proxy_max_temp_file_size 0;
  234. }
  235. }
  236. {% endif %}