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.
 
 

247 lignes
8.4 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. {#
  94. This handles the Matrix Client API only.
  95. The Matrix Federation API is handled by a separate vhost.
  96. #}
  97. location ~* ^({{ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes|join('|') }}) {
  98. {% if matrix_nginx_proxy_enabled %}
  99. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  100. resolver 127.0.0.11 valid=5s;
  101. set $backend "{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container }}";
  102. proxy_pass http://$backend;
  103. {% else %}
  104. {# Generic configuration for use outside of our container setup #}
  105. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_sans_container }};
  106. {% endif %}
  107. proxy_set_header Host $host;
  108. proxy_set_header X-Forwarded-For $remote_addr;
  109. client_body_buffer_size 25M;
  110. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  111. proxy_max_temp_file_size 0;
  112. }
  113. location / {
  114. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  115. return 302 $scheme://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  116. {% else %}
  117. rewrite ^/$ /_matrix/static/ last;
  118. {% endif %}
  119. }
  120. {% endmacro %}
  121. server {
  122. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  123. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  124. server_tokens off;
  125. root /dev/null;
  126. {% if matrix_nginx_proxy_https_enabled %}
  127. location /.well-known/acme-challenge {
  128. {% if matrix_nginx_proxy_enabled %}
  129. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  130. resolver 127.0.0.11 valid=5s;
  131. set $backend "matrix-certbot:8080";
  132. proxy_pass http://$backend;
  133. {% else %}
  134. {# Generic configuration for use outside of our container setup #}
  135. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  136. {% endif %}
  137. }
  138. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  139. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  140. {% endif %}
  141. location / {
  142. return 301 https://$http_host$request_uri;
  143. }
  144. {% else %}
  145. {{ render_vhost_directives() }}
  146. {% endif %}
  147. }
  148. {% if matrix_nginx_proxy_https_enabled %}
  149. server {
  150. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  151. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  152. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  153. server_tokens off;
  154. root /dev/null;
  155. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  156. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  157. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  158. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  159. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  160. {% endif %}
  161. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  162. {{ render_vhost_directives() }}
  163. }
  164. {% endif %}
  165. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  166. {#
  167. This federation vhost is a little special.
  168. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  169. #}
  170. server {
  171. {% if matrix_nginx_proxy_https_enabled %}
  172. listen 8448 ssl http2;
  173. listen [::]:8448 ssl http2;
  174. {% else %}
  175. listen 8448;
  176. {% endif %}
  177. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  178. server_tokens off;
  179. root /dev/null;
  180. gzip on;
  181. gzip_types text/plain application/json;
  182. {% if matrix_nginx_proxy_https_enabled %}
  183. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  184. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  185. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  186. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  187. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  188. {% endif %}
  189. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  190. {% endif %}
  191. location / {
  192. {% if matrix_nginx_proxy_enabled %}
  193. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  194. resolver 127.0.0.11 valid=5s;
  195. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  196. proxy_pass http://$backend;
  197. {% else %}
  198. {# Generic configuration for use outside of our container setup #}
  199. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  200. {% endif %}
  201. proxy_set_header Host $host;
  202. proxy_set_header X-Forwarded-For $remote_addr;
  203. client_body_buffer_size 25M;
  204. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  205. proxy_max_temp_file_size 0;
  206. }
  207. }
  208. {% endif %}