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.
 
 

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