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.
 
 

199 lines
6.8 KiB

  1. #jinja2: lstrip_blocks: "True"
  2. server {
  3. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  4. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  5. server_tokens off;
  6. location /.well-known/acme-challenge {
  7. {% if matrix_nginx_proxy_enabled %}
  8. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  9. resolver 127.0.0.11 valid=5s;
  10. set $backend "matrix-certbot:8080";
  11. proxy_pass http://$backend;
  12. {% else %}
  13. {# Generic configuration for use outside of our container setup #}
  14. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  15. {% endif %}
  16. }
  17. location / {
  18. return 301 https://$http_host$request_uri;
  19. }
  20. }
  21. server {
  22. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  23. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  24. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  25. server_tokens off;
  26. root /dev/null;
  27. gzip on;
  28. gzip_types text/plain application/json;
  29. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  30. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  31. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  32. ssl_prefer_server_ciphers on;
  33. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
  34. location /.well-known/matrix {
  35. root {{ matrix_static_files_base_path }};
  36. {#
  37. A somewhat long expires value is used to prevent outages
  38. in case this is unreachable due to network failure or
  39. due to the base domain's server completely dying.
  40. #}
  41. expires 4h;
  42. default_type application/json;
  43. add_header Access-Control-Allow-Origin *;
  44. }
  45. {% if matrix_nginx_proxy_proxy_matrix_corporal_api_enabled %}
  46. location /_matrix/corporal {
  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_corporal_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_corporal_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_identity_api_enabled %}
  61. location /_matrix/identity {
  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_identity_api_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_identity_api_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_user_directory_search_enabled %}
  76. location /_matrix/client/r0/user_directory/search {
  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_user_directory_search_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_user_directory_search_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 {
  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. {% if matrix_nginx_proxy_proxy_synapse_metrics %}
  114. location /_synapse/metrics {
  115. {% if matrix_nginx_proxy_enabled %}
  116. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  117. resolver 127.0.0.11 valid=5s;
  118. set $backend "{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_with_container }}";
  119. proxy_pass http://$backend;
  120. {% else %}
  121. {# Generic configuration for use outside of our container setup #}
  122. proxy_pass http://{{ matrix_nginx_proxy_proxy_synapse_metrics_addr_sans_container }};
  123. {% endif %}
  124. proxy_set_header Host $host;
  125. proxy_set_header X-Forwarded-For $remote_addr;
  126. {% if matrix_nginx_proxy_proxy_synapse_metrics_basic_auth_enabled %}
  127. auth_basic "protected";
  128. auth_basic_user_file /nginx-data/matrix-synapse-metrics-htpasswd;
  129. {% endif %}
  130. }
  131. {% endif %}
  132. location / {
  133. rewrite ^/$ /_matrix/static/ last;
  134. }
  135. }
  136. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  137. server {
  138. listen 8448 ssl http2;
  139. listen [::]:8448 ssl http2;
  140. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  141. server_tokens off;
  142. root /dev/null;
  143. gzip on;
  144. gzip_types text/plain application/json;
  145. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  146. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  147. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  148. ssl_prefer_server_ciphers on;
  149. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
  150. location / {
  151. {% if matrix_nginx_proxy_enabled %}
  152. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  153. resolver 127.0.0.11 valid=5s;
  154. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  155. proxy_pass http://$backend;
  156. {% else %}
  157. {# Generic configuration for use outside of our container setup #}
  158. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  159. {% endif %}
  160. proxy_set_header Host $host;
  161. proxy_set_header X-Forwarded-For $remote_addr;
  162. client_body_buffer_size 25M;
  163. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  164. proxy_max_temp_file_size 0;
  165. }
  166. }
  167. {% endif %}