Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 

300 lignes
12 KiB

  1. #jinja2: lstrip_blocks: "True"
  2. {% macro render_nginx_status_location_block(addresses) %}
  3. {# Empty first line to make indentation prettier. #}
  4. location /nginx_status {
  5. stub_status on;
  6. access_log off;
  7. {% for address in addresses %}
  8. allow {{ address }};
  9. {% endfor %}
  10. deny all;
  11. }
  12. {% endmacro %}
  13. {% macro render_vhost_directives() %}
  14. gzip on;
  15. gzip_types text/plain application/json;
  16. location /.well-known/matrix {
  17. root {{ matrix_static_files_base_path }};
  18. {#
  19. A somewhat long expires value is used to prevent outages
  20. in case this is unreachable due to network failure or
  21. due to the base domain's server completely dying.
  22. #}
  23. expires 4h;
  24. default_type application/json;
  25. add_header Access-Control-Allow-Origin *;
  26. }
  27. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  28. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  29. {% endif %}
  30. {% if matrix_nginx_proxy_proxy_matrix_corporal_api_enabled %}
  31. location ^~ /_matrix/corporal {
  32. {% if matrix_nginx_proxy_enabled %}
  33. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  34. resolver 127.0.0.11 valid=5s;
  35. set $backend "{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_with_container }}";
  36. proxy_pass http://$backend;
  37. {% else %}
  38. {# Generic configuration for use outside of our container setup #}
  39. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_sans_container }};
  40. {% endif %}
  41. proxy_set_header Host $host;
  42. proxy_set_header X-Forwarded-For $remote_addr;
  43. }
  44. {% endif %}
  45. {% if matrix_nginx_proxy_proxy_matrix_identity_api_enabled %}
  46. location ^~ /_matrix/identity {
  47. {% if matrix_nginx_proxy_enabled %}
  48. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  49. resolver 127.0.0.11 valid=5s;
  50. set $backend "{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_with_container }}";
  51. proxy_pass http://$backend;
  52. {% else %}
  53. {# Generic configuration for use outside of our container setup #}
  54. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_sans_container }};
  55. {% endif %}
  56. proxy_set_header Host $host;
  57. proxy_set_header X-Forwarded-For $remote_addr;
  58. }
  59. {% endif %}
  60. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled %}
  61. location ^~ /_matrix/client/r0/user_directory/search {
  62. {% if matrix_nginx_proxy_enabled %}
  63. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  64. resolver 127.0.0.11 valid=5s;
  65. set $backend "{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_with_container }}";
  66. proxy_pass http://$backend;
  67. {% else %}
  68. {# Generic configuration for use outside of our container setup #}
  69. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_sans_container }};
  70. {% endif %}
  71. proxy_set_header Host $host;
  72. proxy_set_header X-Forwarded-For $remote_addr;
  73. }
  74. {% endif %}
  75. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_enabled %}
  76. location ~ ^/_matrix/client/r0/register/(email|msisdn)/requestToken$ {
  77. {% if matrix_nginx_proxy_enabled %}
  78. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  79. resolver 127.0.0.11 valid=5s;
  80. set $backend "{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_with_container }}";
  81. proxy_pass http://$backend;
  82. {% else %}
  83. {# Generic configuration for use outside of our container setup #}
  84. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_sans_container }};
  85. {% endif %}
  86. proxy_set_header Host $host;
  87. proxy_set_header X-Forwarded-For $remote_addr;
  88. }
  89. {% endif %}
  90. {% for configuration_block in matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks %}
  91. {{- configuration_block }}
  92. {% endfor %}
  93. {% if matrix_nginx_proxy_proxy_synapse_metrics %}
  94. location /_synapse/metrics {
  95. {% if matrix_nginx_proxy_enabled %}
  96. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  97. resolver 127.0.0.11 valid=5s;
  98. set $backend "{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_with_container }}";
  99. proxy_pass http://$backend;
  100. {% else %}
  101. {# Generic configuration for use outside of our container setup #}
  102. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_sans_container }};
  103. {% endif %}
  104. proxy_set_header Host $host;
  105. proxy_set_header X-Forwarded-For $remote_addr;
  106. {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %}
  107. auth_basic "protected";
  108. auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd;
  109. {% endif %}
  110. }
  111. {% endif %}
  112. {#
  113. This handles the Matrix Client API only.
  114. The Matrix Federation API is handled by a separate vhost.
  115. #}
  116. location ~* ^({{ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes|join('|') }}) {
  117. {% if matrix_nginx_proxy_enabled %}
  118. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  119. resolver 127.0.0.11 valid=5s;
  120. set $backend "{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container }}";
  121. proxy_pass http://$backend;
  122. {% else %}
  123. {# Generic configuration for use outside of our container setup #}
  124. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_sans_container }};
  125. {% endif %}
  126. proxy_set_header Host $host;
  127. proxy_set_header X-Forwarded-For $remote_addr;
  128. client_body_buffer_size 25M;
  129. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  130. proxy_max_temp_file_size 0;
  131. }
  132. location / {
  133. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  134. return 302 $scheme://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  135. {% else %}
  136. rewrite ^/$ /_matrix/static/ last;
  137. {% endif %}
  138. }
  139. {% endmacro %}
  140. server {
  141. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  142. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  143. server_tokens off;
  144. root /dev/null;
  145. {% if matrix_nginx_proxy_https_enabled %}
  146. location /.well-known/acme-challenge {
  147. {% if matrix_nginx_proxy_enabled %}
  148. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  149. resolver 127.0.0.11 valid=5s;
  150. set $backend "matrix-certbot:8080";
  151. proxy_pass http://$backend;
  152. {% else %}
  153. {# Generic configuration for use outside of our container setup #}
  154. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  155. {% endif %}
  156. }
  157. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  158. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  159. {% endif %}
  160. location / {
  161. return 301 https://$http_host$request_uri;
  162. }
  163. {% else %}
  164. {{ render_vhost_directives() }}
  165. {% endif %}
  166. }
  167. {% if matrix_nginx_proxy_https_enabled %}
  168. server {
  169. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  170. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  171. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  172. server_tokens off;
  173. root /dev/null;
  174. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  175. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  176. {% if matrix_nginx_proxy_ssl_config == "Modern" %}
  177. ssl_protocols TLSv1.3;
  178. ssl_prefer_server_ciphers off;
  179. {% elif matrix_nginx_proxy_ssl_config == "Intermediate" %}
  180. ssl_protocols TLSv1.2 TLSv1.3;
  181. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  182. ssl_prefer_server_ciphers off;
  183. {% elif matrix_nginx_proxy_ssl_config == "Old" %}
  184. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  185. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA;
  186. ssl_prefer_server_ciphers on;
  187. {% elif matrix_nginx_proxy_ssl_config == "Custom" %}
  188. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  189. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  190. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  191. {% endif %}
  192. {{ render_vhost_directives() }}
  193. }
  194. {% endif %}
  195. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  196. {#
  197. This federation vhost is a little special.
  198. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  199. #}
  200. server {
  201. {% if matrix_nginx_proxy_https_enabled %}
  202. listen 8448 ssl http2;
  203. listen [::]:8448 ssl http2;
  204. {% else %}
  205. listen 8448;
  206. {% endif %}
  207. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  208. server_tokens off;
  209. root /dev/null;
  210. gzip on;
  211. gzip_types text/plain application/json;
  212. {% if matrix_nginx_proxy_https_enabled %}
  213. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  214. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  215. {% if matrix_nginx_proxy_ssl_config == "Modern" %}
  216. ssl_protocols TLSv1.3;
  217. ssl_prefer_server_ciphers off;
  218. {% elif matrix_nginx_proxy_ssl_config == "Intermediate" %}
  219. ssl_protocols TLSv1.2 TLSv1.3;
  220. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  221. ssl_prefer_server_ciphers off;
  222. {% elif matrix_nginx_proxy_ssl_config == "Old" %}
  223. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  224. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA;
  225. ssl_prefer_server_ciphers on;
  226. {% elif matrix_nginx_proxy_ssl_config == "Custom" %}
  227. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  228. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  229. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  230. {% endif %}
  231. {% endif %}
  232. location / {
  233. {% if matrix_nginx_proxy_enabled %}
  234. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  235. resolver 127.0.0.11 valid=5s;
  236. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  237. proxy_pass http://$backend;
  238. {% else %}
  239. {# Generic configuration for use outside of our container setup #}
  240. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  241. {% endif %}
  242. proxy_set_header Host $host;
  243. proxy_set_header X-Forwarded-For $remote_addr;
  244. client_body_buffer_size 25M;
  245. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  246. proxy_max_temp_file_size 0;
  247. }
  248. }
  249. {% endif %}