Matrix Docker Ansible eploy
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

286 wiersze
10 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. {#
  121. We only handle the root URI for this redirect or homepage serving.
  122. Unhandled URIs (mostly by `matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes` above) should result in a 404,
  123. instead of causing a redirect.
  124. See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1058
  125. #}
  126. location ~* ^/$ {
  127. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  128. return 302 $scheme://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  129. {% else %}
  130. rewrite ^/$ /_matrix/static/ last;
  131. {% endif %}
  132. }
  133. {% endmacro %}
  134. server {
  135. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  136. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  137. server_tokens off;
  138. root /dev/null;
  139. {% if matrix_nginx_proxy_https_enabled %}
  140. location /.well-known/acme-challenge {
  141. {% if matrix_nginx_proxy_enabled %}
  142. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  143. resolver 127.0.0.11 valid=5s;
  144. set $backend "matrix-certbot:8080";
  145. proxy_pass http://$backend;
  146. {% else %}
  147. {# Generic configuration for use outside of our container setup #}
  148. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  149. {% endif %}
  150. }
  151. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  152. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  153. {% endif %}
  154. location / {
  155. return 301 https://$http_host$request_uri;
  156. }
  157. {% else %}
  158. {{ render_vhost_directives() }}
  159. {% endif %}
  160. }
  161. {% if matrix_nginx_proxy_https_enabled %}
  162. server {
  163. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  164. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  165. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  166. server_tokens off;
  167. root /dev/null;
  168. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  169. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  170. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  171. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  172. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  173. {% endif %}
  174. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  175. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  176. ssl_stapling on;
  177. ssl_stapling_verify on;
  178. ssl_trusted_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/chain.pem;
  179. {% endif %}
  180. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  181. ssl_session_tickets off;
  182. {% endif %}
  183. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  184. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  185. {{ render_vhost_directives() }}
  186. }
  187. {% endif %}
  188. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  189. {#
  190. This federation vhost is a little special.
  191. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  192. #}
  193. server {
  194. {% if matrix_nginx_proxy_https_enabled %}
  195. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  196. listen [::]:{{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  197. {% else %}
  198. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }};
  199. {% endif %}
  200. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  201. server_tokens off;
  202. root /dev/null;
  203. gzip on;
  204. gzip_types text/plain application/json;
  205. {% if matrix_nginx_proxy_https_enabled %}
  206. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  207. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  208. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  209. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  210. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  211. {% endif %}
  212. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  213. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  214. ssl_stapling on;
  215. ssl_stapling_verify on;
  216. ssl_trusted_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_trusted_certificate }};
  217. {% endif %}
  218. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  219. ssl_session_tickets off;
  220. {% endif %}
  221. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  222. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  223. {% endif %}
  224. location / {
  225. {% if matrix_nginx_proxy_enabled %}
  226. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  227. resolver 127.0.0.11 valid=5s;
  228. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  229. proxy_pass http://$backend;
  230. {% else %}
  231. {# Generic configuration for use outside of our container setup #}
  232. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  233. {% endif %}
  234. proxy_set_header Host $host;
  235. proxy_set_header X-Forwarded-For $remote_addr;
  236. proxy_set_header X-Forwarded-Proto $scheme;
  237. client_body_buffer_size 25M;
  238. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  239. proxy_max_temp_file_size 0;
  240. }
  241. }
  242. {% endif %}