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.
 
 

259 line
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. }
  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. rewrite ^/$ /_matrix/static/ last;
  134. }
  135. {% endmacro %}
  136. server {
  137. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  138. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  139. server_tokens off;
  140. root /dev/null;
  141. {% if matrix_nginx_proxy_https_enabled %}
  142. location /.well-known/acme-challenge {
  143. {% if matrix_nginx_proxy_enabled %}
  144. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  145. resolver 127.0.0.11 valid=5s;
  146. set $backend "matrix-certbot:8080";
  147. proxy_pass http://$backend;
  148. {% else %}
  149. {# Generic configuration for use outside of our container setup #}
  150. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  151. {% endif %}
  152. }
  153. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  154. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  155. {% endif %}
  156. location / {
  157. return 301 https://$http_host$request_uri;
  158. }
  159. {% else %}
  160. {{ render_vhost_directives() }}
  161. {% endif %}
  162. }
  163. {% if matrix_nginx_proxy_https_enabled %}
  164. server {
  165. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  166. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  167. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  168. server_tokens off;
  169. root /dev/null;
  170. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  171. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  172. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  173. ssl_prefer_server_ciphers on;
  174. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
  175. {{ render_vhost_directives() }}
  176. }
  177. {% endif %}
  178. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  179. {#
  180. This federation vhost is a little special.
  181. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  182. #}
  183. server {
  184. {% if matrix_nginx_proxy_https_enabled %}
  185. listen 8448 ssl http2;
  186. listen [::]:8448 ssl http2;
  187. {% else %}
  188. listen 8448;
  189. {% endif %}
  190. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  191. server_tokens off;
  192. root /dev/null;
  193. gzip on;
  194. gzip_types text/plain application/json;
  195. {% if matrix_nginx_proxy_https_enabled %}
  196. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  197. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  198. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  199. ssl_prefer_server_ciphers on;
  200. ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
  201. {% endif %}
  202. location / {
  203. {% if matrix_nginx_proxy_enabled %}
  204. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  205. resolver 127.0.0.11 valid=5s;
  206. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  207. proxy_pass http://$backend;
  208. {% else %}
  209. {# Generic configuration for use outside of our container setup #}
  210. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  211. {% endif %}
  212. proxy_set_header Host $host;
  213. proxy_set_header X-Forwarded-For $remote_addr;
  214. client_body_buffer_size 25M;
  215. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  216. proxy_max_temp_file_size 0;
  217. }
  218. }
  219. {% endif %}