Matrix Docker Ansible eploy
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 

309 行
12 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. {% if matrix_nginx_proxy_hsts_preload_enabled %}
  20. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
  21. {% else %}
  22. add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
  23. {% endif %}
  24. add_header X-XSS-Protection "{{ matrix_nginx_proxy_xss_protection }}";
  25. location /.well-known/matrix {
  26. root {{ matrix_static_files_base_path }};
  27. {#
  28. A somewhat long expires value is used to prevent outages
  29. in case this is unreachable due to network failure or
  30. due to the base domain's server completely dying.
  31. #}
  32. expires 4h;
  33. default_type application/json;
  34. add_header Access-Control-Allow-Origin *;
  35. }
  36. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  37. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  38. {% endif %}
  39. {% if matrix_nginx_proxy_proxy_matrix_metrics_enabled %}
  40. location /metrics {
  41. {% if matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_enabled %}
  42. auth_basic "protected";
  43. auth_basic_user_file {{ matrix_nginx_proxy_proxy_matrix_metrics_basic_auth_path }};
  44. {% endif %}
  45. {% for configuration_block in matrix_nginx_proxy_proxy_matrix_metrics_additional_location_configuration_blocks %}
  46. {{- configuration_block }}
  47. {% endfor %}
  48. }
  49. {% endif %}
  50. {% if matrix_nginx_proxy_proxy_matrix_corporal_api_enabled %}
  51. location ^~ /_matrix/corporal {
  52. {% if matrix_nginx_proxy_enabled %}
  53. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  54. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  55. set $backend "{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_with_container }}";
  56. proxy_pass http://$backend;
  57. {% else %}
  58. {# Generic configuration for use outside of our container setup #}
  59. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_corporal_api_addr_sans_container }};
  60. {% endif %}
  61. proxy_set_header Host $host;
  62. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  63. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  64. }
  65. {% endif %}
  66. {% if matrix_nginx_proxy_proxy_matrix_identity_api_enabled %}
  67. location ^~ /_matrix/identity {
  68. {% if matrix_nginx_proxy_enabled %}
  69. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  70. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  71. set $backend "{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_with_container }}";
  72. proxy_pass http://$backend;
  73. {% else %}
  74. {# Generic configuration for use outside of our container setup #}
  75. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_identity_api_addr_sans_container }};
  76. {% endif %}
  77. proxy_set_header Host $host;
  78. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  79. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  80. }
  81. {% endif %}
  82. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled %}
  83. location ^~ /_matrix/client/r0/user_directory/search {
  84. {% if matrix_nginx_proxy_enabled %}
  85. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  86. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  87. set $backend "{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_with_container }}";
  88. proxy_pass http://$backend;
  89. {% else %}
  90. {# Generic configuration for use outside of our container setup #}
  91. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_sans_container }};
  92. {% endif %}
  93. proxy_set_header Host $host;
  94. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  95. }
  96. {% endif %}
  97. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_enabled %}
  98. location ~ ^/_matrix/client/r0/register/(email|msisdn)/requestToken$ {
  99. {% if matrix_nginx_proxy_enabled %}
  100. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  101. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  102. set $backend "{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_with_container }}";
  103. proxy_pass http://$backend;
  104. {% else %}
  105. {# Generic configuration for use outside of our container setup #}
  106. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_sans_container }};
  107. {% endif %}
  108. proxy_set_header Host $host;
  109. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  110. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  111. }
  112. {% endif %}
  113. {% for configuration_block in matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks %}
  114. {{- configuration_block }}
  115. {% endfor %}
  116. {#
  117. This handles the Matrix Client API only.
  118. The Matrix Federation API is handled by a separate vhost.
  119. #}
  120. location ~* ^({{ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes|join('|') }}) {
  121. {% if matrix_nginx_proxy_enabled %}
  122. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  123. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  124. set $backend "{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container }}";
  125. proxy_pass http://$backend;
  126. {% else %}
  127. {# Generic configuration for use outside of our container setup #}
  128. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_sans_container }};
  129. {% endif %}
  130. proxy_set_header Host $host;
  131. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  132. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  133. client_body_buffer_size 25M;
  134. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  135. proxy_max_temp_file_size 0;
  136. }
  137. {#
  138. We only handle the root URI for this redirect or homepage serving.
  139. Unhandled URIs (mostly by `matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes` above) should result in a 404,
  140. instead of causing a redirect.
  141. See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1058
  142. #}
  143. location ~* ^/$ {
  144. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  145. return 302 {{ matrix_nginx_proxy_x_forwarded_proto_value }}://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  146. {% else %}
  147. rewrite ^/$ /_matrix/static/ last;
  148. {% endif %}
  149. }
  150. {% endmacro %}
  151. server {
  152. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  153. listen [::]:{{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  154. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  155. server_tokens off;
  156. root /dev/null;
  157. {% if matrix_nginx_proxy_https_enabled %}
  158. location /.well-known/acme-challenge {
  159. {% if matrix_nginx_proxy_enabled %}
  160. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  161. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  162. set $backend "matrix-certbot:8080";
  163. proxy_pass http://$backend;
  164. {% else %}
  165. {# Generic configuration for use outside of our container setup #}
  166. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  167. {% endif %}
  168. }
  169. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  170. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  171. {% endif %}
  172. location / {
  173. return 301 https://$http_host$request_uri;
  174. }
  175. {% else %}
  176. {{ render_vhost_directives() }}
  177. {% endif %}
  178. }
  179. {% if matrix_nginx_proxy_https_enabled %}
  180. server {
  181. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  182. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  183. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  184. server_tokens off;
  185. root /dev/null;
  186. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  187. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  188. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  189. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  190. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  191. {% endif %}
  192. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  193. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  194. ssl_stapling on;
  195. ssl_stapling_verify on;
  196. ssl_trusted_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/chain.pem;
  197. {% endif %}
  198. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  199. ssl_session_tickets off;
  200. {% endif %}
  201. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  202. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  203. {{ render_vhost_directives() }}
  204. }
  205. {% endif %}
  206. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  207. {#
  208. This federation vhost is a little special.
  209. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  210. #}
  211. server {
  212. {% if matrix_nginx_proxy_https_enabled %}
  213. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  214. listen [::]:{{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  215. {% else %}
  216. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }};
  217. {% endif %}
  218. server_name {{ matrix_nginx_proxy_proxy_matrix_federation_hostname }};
  219. server_tokens off;
  220. root /dev/null;
  221. gzip on;
  222. gzip_types text/plain application/json;
  223. {% if matrix_nginx_proxy_https_enabled %}
  224. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  225. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  226. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  227. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  228. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  229. {% endif %}
  230. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  231. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  232. ssl_stapling on;
  233. ssl_stapling_verify on;
  234. ssl_trusted_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_trusted_certificate }};
  235. {% endif %}
  236. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  237. ssl_session_tickets off;
  238. {% endif %}
  239. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  240. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  241. {% endif %}
  242. location / {
  243. {% if matrix_nginx_proxy_enabled %}
  244. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  245. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  246. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  247. proxy_pass http://$backend;
  248. {% else %}
  249. {# Generic configuration for use outside of our container setup #}
  250. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  251. {% endif %}
  252. proxy_set_header Host $host;
  253. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  254. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  255. client_body_buffer_size 25M;
  256. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  257. proxy_max_temp_file_size 0;
  258. }
  259. }
  260. {% endif %}