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.
 
 

256 line
8.9 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. {% if matrix_nginx_proxy_floc_optout_enabled %}
  17. add_header Permissions-Policy interest-cohort=() always;
  18. {% endif %}
  19. location /.well-known/matrix {
  20. root {{ matrix_static_files_base_path }};
  21. {#
  22. A somewhat long expires value is used to prevent outages
  23. in case this is unreachable due to network failure or
  24. due to the base domain's server completely dying.
  25. #}
  26. expires 4h;
  27. default_type application/json;
  28. add_header Access-Control-Allow-Origin *;
  29. }
  30. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  31. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  32. {% endif %}
  33. {% if matrix_nginx_proxy_proxy_matrix_corporal_api_enabled %}
  34. location ^~ /_matrix/corporal {
  35. {% if matrix_nginx_proxy_enabled %}
  36. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  37. resolver 127.0.0.11 valid=5s;
  38. set $backend "{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_with_container }}";
  39. proxy_pass http://$backend;
  40. {% else %}
  41. {# Generic configuration for use outside of our container setup #}
  42. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_sans_container }};
  43. {% endif %}
  44. proxy_set_header Host $host;
  45. proxy_set_header X-Forwarded-For $remote_addr;
  46. proxy_set_header X-Forwarded-Proto $scheme;
  47. }
  48. {% endif %}
  49. {% if matrix_nginx_proxy_proxy_matrix_identity_api_enabled %}
  50. location ^~ /_matrix/identity {
  51. {% if matrix_nginx_proxy_enabled %}
  52. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  53. resolver 127.0.0.11 valid=5s;
  54. set $backend "{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_with_container }}";
  55. proxy_pass http://$backend;
  56. {% else %}
  57. {# Generic configuration for use outside of our container setup #}
  58. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_sans_container }};
  59. {% endif %}
  60. proxy_set_header Host $host;
  61. proxy_set_header X-Forwarded-For $remote_addr;
  62. proxy_set_header X-Forwarded-Proto $scheme;
  63. }
  64. {% endif %}
  65. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled %}
  66. location ^~ /_matrix/client/r0/user_directory/search {
  67. {% if matrix_nginx_proxy_enabled %}
  68. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  69. resolver 127.0.0.11 valid=5s;
  70. set $backend "{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_with_container }}";
  71. proxy_pass http://$backend;
  72. {% else %}
  73. {# Generic configuration for use outside of our container setup #}
  74. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_sans_container }};
  75. {% endif %}
  76. proxy_set_header Host $host;
  77. proxy_set_header X-Forwarded-For $remote_addr;
  78. }
  79. {% endif %}
  80. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_enabled %}
  81. location ~ ^/_matrix/client/r0/register/(email|msisdn)/requestToken$ {
  82. {% if matrix_nginx_proxy_enabled %}
  83. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  84. resolver 127.0.0.11 valid=5s;
  85. set $backend "{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_with_container }}";
  86. proxy_pass http://$backend;
  87. {% else %}
  88. {# Generic configuration for use outside of our container setup #}
  89. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_sans_container }};
  90. {% endif %}
  91. proxy_set_header Host $host;
  92. proxy_set_header X-Forwarded-For $remote_addr;
  93. proxy_set_header X-Forwarded-Proto $scheme;
  94. }
  95. {% endif %}
  96. {% for configuration_block in matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks %}
  97. {{- configuration_block }}
  98. {% endfor %}
  99. {#
  100. This handles the Matrix Client API only.
  101. The Matrix Federation API is handled by a separate vhost.
  102. #}
  103. location ~* ^({{ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes|join('|') }}) {
  104. {% if matrix_nginx_proxy_enabled %}
  105. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  106. resolver 127.0.0.11 valid=5s;
  107. set $backend "{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container }}";
  108. proxy_pass http://$backend;
  109. {% else %}
  110. {# Generic configuration for use outside of our container setup #}
  111. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_sans_container }};
  112. {% endif %}
  113. proxy_set_header Host $host;
  114. proxy_set_header X-Forwarded-For $remote_addr;
  115. proxy_set_header X-Forwarded-Proto $scheme;
  116. client_body_buffer_size 25M;
  117. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  118. proxy_max_temp_file_size 0;
  119. }
  120. location / {
  121. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  122. return 302 $scheme://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  123. {% else %}
  124. rewrite ^/$ /_matrix/static/ last;
  125. {% endif %}
  126. }
  127. {% endmacro %}
  128. server {
  129. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  130. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  131. server_tokens off;
  132. root /dev/null;
  133. {% if matrix_nginx_proxy_https_enabled %}
  134. location /.well-known/acme-challenge {
  135. {% if matrix_nginx_proxy_enabled %}
  136. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  137. resolver 127.0.0.11 valid=5s;
  138. set $backend "matrix-certbot:8080";
  139. proxy_pass http://$backend;
  140. {% else %}
  141. {# Generic configuration for use outside of our container setup #}
  142. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  143. {% endif %}
  144. }
  145. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  146. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  147. {% endif %}
  148. location / {
  149. return 301 https://$http_host$request_uri;
  150. }
  151. {% else %}
  152. {{ render_vhost_directives() }}
  153. {% endif %}
  154. }
  155. {% if matrix_nginx_proxy_https_enabled %}
  156. server {
  157. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  158. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  159. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  160. server_tokens off;
  161. root /dev/null;
  162. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  163. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  164. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  165. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  166. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  167. {% endif %}
  168. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  169. {{ render_vhost_directives() }}
  170. }
  171. {% endif %}
  172. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  173. {#
  174. This federation vhost is a little special.
  175. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  176. #}
  177. server {
  178. {% if matrix_nginx_proxy_https_enabled %}
  179. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  180. listen [::]:{{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  181. {% else %}
  182. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }};
  183. {% endif %}
  184. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  185. server_tokens off;
  186. root /dev/null;
  187. gzip on;
  188. gzip_types text/plain application/json;
  189. {% if matrix_nginx_proxy_https_enabled %}
  190. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  191. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  192. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  193. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  194. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  195. {% endif %}
  196. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  197. {% endif %}
  198. location / {
  199. {% if matrix_nginx_proxy_enabled %}
  200. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  201. resolver 127.0.0.11 valid=5s;
  202. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  203. proxy_pass http://$backend;
  204. {% else %}
  205. {# Generic configuration for use outside of our container setup #}
  206. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  207. {% endif %}
  208. proxy_set_header Host $host;
  209. proxy_set_header X-Forwarded-For $remote_addr;
  210. proxy_set_header X-Forwarded-Proto $scheme;
  211. client_body_buffer_size 25M;
  212. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  213. proxy_max_temp_file_size 0;
  214. }
  215. }
  216. {% endif %}