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.
 
 

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