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.
 
 

270 lines
9.2 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. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  177. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  178. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  179. {% endif %}
  180. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  181. {{ render_vhost_directives() }}
  182. }
  183. {% endif %}
  184. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  185. {#
  186. This federation vhost is a little special.
  187. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  188. #}
  189. server {
  190. {% if matrix_nginx_proxy_https_enabled %}
  191. listen 8448 ssl http2;
  192. listen [::]:8448 ssl http2;
  193. {% else %}
  194. listen 8448;
  195. {% endif %}
  196. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  197. server_tokens off;
  198. root /dev/null;
  199. gzip on;
  200. gzip_types text/plain application/json;
  201. {% if matrix_nginx_proxy_https_enabled %}
  202. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  203. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  204. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  205. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  206. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  207. {% endif %}
  208. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  209. {% endif %}
  210. location / {
  211. {% if matrix_nginx_proxy_enabled %}
  212. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  213. resolver 127.0.0.11 valid=5s;
  214. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  215. proxy_pass http://$backend;
  216. {% else %}
  217. {# Generic configuration for use outside of our container setup #}
  218. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  219. {% endif %}
  220. proxy_set_header Host $host;
  221. proxy_set_header X-Forwarded-For $remote_addr;
  222. client_body_buffer_size 25M;
  223. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  224. proxy_max_temp_file_size 0;
  225. }
  226. }
  227. {% endif %}