Matrix Docker Ansible eploy
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

414 řádky
16 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_media_repo_enabled %}
  83. # Redirect all media endpoints to the media-repo
  84. location ^~ /_matrix/media {
  85. {% if matrix_nginx_proxy_enabled %}
  86. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  87. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  88. set $backend "{{ matrix_nginx_proxy_proxy_media_repo_addr_with_container }}";
  89. proxy_pass http://$backend;
  90. {% else %}
  91. {# Generic configuration for use outside of our container setup #}
  92. proxy_pass http://{{ matrix_nginx_proxy_proxy_media_repo_addr_sans_container }};
  93. {% endif %}
  94. # Make sure this matches your homeserver in media-repo.yaml
  95. # You may have to manually specify it if using delegation or the
  96. # incoming Host doesn't match.
  97. proxy_set_header Host $host;
  98. proxy_set_header X-Real-IP $remote_addr;
  99. proxy_set_header X-Forwarded-For $remote_addr;
  100. client_body_buffer_size {{ ((matrix_media_repo_max_bytes | int) / 4) | int }};
  101. client_max_body_size {{ matrix_media_repo_max_bytes }};
  102. }
  103. # Redirect other endpoints registered by the media-repo to its container
  104. # /_matrix/client/r0/logout
  105. # /_matrix/client/r0/logout/all
  106. location ~ ^/_matrix/client/(r0|v1|v3|unstable)/(logout|logout/all) {
  107. {% if matrix_nginx_proxy_enabled %}
  108. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  109. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  110. set $backend "{{ matrix_nginx_proxy_proxy_media_repo_addr_with_container }}";
  111. proxy_pass http://$backend;
  112. {% else %}
  113. {# Generic configuration for use outside of our container setup #}
  114. proxy_pass http://{{ matrix_nginx_proxy_proxy_media_repo_addr_sans_container }};
  115. {% endif %}
  116. # Make sure this matches your homeserver in media-repo.yaml
  117. # You may have to manually specify it if using delegation or the
  118. # incoming Host doesn't match.
  119. proxy_set_header Host $host;
  120. proxy_set_header X-Real-IP $remote_addr;
  121. proxy_set_header X-Forwarded-For $remote_addr;
  122. }
  123. # Redirect other endpoints registered by the media-repo to its container
  124. # /_matrix/client/r0/admin/purge_media_cache
  125. # /_matrix/client/r0/admin/quarantine_media/{roomId:[^/]+}
  126. location ~ ^/_matrix/client/(r0|v1|v3|unstable)/admin/(purge_media_cache|quarantine_media/.*) {
  127. {% if matrix_nginx_proxy_enabled %}
  128. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  129. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  130. set $backend "{{ matrix_nginx_proxy_proxy_media_repo_addr_with_container }}";
  131. proxy_pass http://$backend;
  132. {% else %}
  133. {# Generic configuration for use outside of our container setup #}
  134. proxy_pass http://{{ matrix_nginx_proxy_proxy_media_repo_addr_sans_container }};
  135. {% endif %}
  136. # Make sure this matches your homeserver in media-repo.yaml
  137. # You may have to manually specify it if using delegation or the
  138. # incoming Host doesn't match.
  139. proxy_set_header Host $host;
  140. proxy_set_header X-Real-IP $remote_addr;
  141. proxy_set_header X-Forwarded-For $remote_addr;
  142. }
  143. # Redirect other endpoints registered by the media-repo to its container
  144. location ^~ /_matrix/client/unstable/io.t2bot.media {
  145. {% if matrix_nginx_proxy_enabled %}
  146. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  147. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  148. set $backend "{{ matrix_nginx_proxy_proxy_media_repo_addr_with_container }}";
  149. proxy_pass http://$backend;
  150. {% else %}
  151. {# Generic configuration for use outside of our container setup #}
  152. proxy_pass http://{{ matrix_nginx_proxy_proxy_media_repo_addr_sans_container }};
  153. {% endif %}
  154. # Make sure this matches your homeserver in media-repo.yaml
  155. # You may have to manually specify it if using delegation or the
  156. # incoming Host doesn't match.
  157. proxy_set_header Host $host;
  158. proxy_set_header X-Real-IP $remote_addr;
  159. proxy_set_header X-Forwarded-For $remote_addr;
  160. }
  161. {% endif %}
  162. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_enabled %}
  163. location ~ ^/_matrix/client/(r0|v3)/user_directory/search {
  164. {% if matrix_nginx_proxy_enabled %}
  165. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  166. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  167. set $backend "{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_with_container }}";
  168. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_v3_to_r0_redirect_enabled %}
  169. rewrite ^(.*?)/v3/(.*?)$ $1/r0/$2 break;
  170. {% endif %}
  171. proxy_pass http://$backend;
  172. {% else %}
  173. {% if matrix_nginx_proxy_proxy_matrix_user_directory_search_v3_to_r0_redirect_enabled %}
  174. rewrite ^(.*?)/v3/(.*?)$ $1/r0/$2 break;
  175. {% endif %}
  176. {# Generic configuration for use outside of our container setup #}
  177. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_user_directory_search_addr_sans_container }};
  178. {% endif %}
  179. proxy_set_header Host $host;
  180. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  181. }
  182. {% endif %}
  183. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_enabled %}
  184. location ~ ^/_matrix/client/(r0|v3)/register/(email|msisdn)/requestToken$ {
  185. {% if matrix_nginx_proxy_enabled %}
  186. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  187. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  188. set $backend "{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_with_container }}";
  189. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_v3_to_r0_redirect_enabled %}
  190. rewrite ^(.*?)/v3/(.*?)$ $1/r0/$2 break;
  191. {% endif %}
  192. proxy_pass http://$backend;
  193. {% else %}
  194. {% if matrix_nginx_proxy_proxy_matrix_3pid_registration_v3_to_r0_redirect_enabled %}
  195. rewrite ^(.*?)/v3/(.*?)$ $1/r0/$2 break;
  196. {% endif %}
  197. {# Generic configuration for use outside of our container setup #}
  198. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_3pid_registration_addr_sans_container }};
  199. {% endif %}
  200. proxy_set_header Host $host;
  201. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  202. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  203. }
  204. {% endif %}
  205. {% for configuration_block in matrix_nginx_proxy_proxy_matrix_additional_server_configuration_blocks %}
  206. {{- configuration_block }}
  207. {% endfor %}
  208. {#
  209. This handles the Matrix Client API only.
  210. The Matrix Federation API is handled by a separate vhost.
  211. #}
  212. location ~* ^({{ matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes|join('|') }}) {
  213. {% if matrix_nginx_proxy_enabled %}
  214. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  215. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  216. set $backend "{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_with_container }}";
  217. proxy_pass http://$backend;
  218. {% else %}
  219. {# Generic configuration for use outside of our container setup #}
  220. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_client_api_addr_sans_container }};
  221. {% endif %}
  222. proxy_set_header Host $host;
  223. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  224. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  225. client_body_buffer_size 25M;
  226. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_client_api_client_max_body_size_mb }}M;
  227. proxy_max_temp_file_size 0;
  228. }
  229. {#
  230. We only handle the root URI for this redirect or homepage serving.
  231. Unhandled URIs (mostly by `matrix_nginx_proxy_proxy_matrix_client_api_forwarded_location_prefix_regexes` above) should result in a 404,
  232. instead of causing a redirect.
  233. See: https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/1058
  234. #}
  235. location ~* ^/$ {
  236. {% if matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain %}
  237. return 302 {{ matrix_nginx_proxy_x_forwarded_proto_value }}://{{ matrix_nginx_proxy_proxy_matrix_client_redirect_root_uri_to_domain }}$request_uri;
  238. {% else %}
  239. rewrite ^/$ /_matrix/static/ last;
  240. {% endif %}
  241. }
  242. {% endmacro %}
  243. server {
  244. listen {{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  245. listen [::]:{{ 8080 if matrix_nginx_proxy_enabled else 80 }};
  246. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  247. server_tokens off;
  248. root /dev/null;
  249. {% if matrix_nginx_proxy_https_enabled %}
  250. location /.well-known/acme-challenge {
  251. {% if matrix_nginx_proxy_enabled %}
  252. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  253. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  254. set $backend "matrix-certbot:8080";
  255. proxy_pass http://$backend;
  256. {% else %}
  257. {# Generic configuration for use outside of our container setup #}
  258. proxy_pass http://127.0.0.1:{{ matrix_ssl_lets_encrypt_certbot_standalone_http_port }};
  259. {% endif %}
  260. }
  261. {% if matrix_nginx_proxy_proxy_matrix_nginx_status_enabled %}
  262. {{ render_nginx_status_location_block(matrix_nginx_proxy_proxy_matrix_nginx_status_allowed_addresses) }}
  263. {% endif %}
  264. location / {
  265. return 301 https://$http_host$request_uri;
  266. }
  267. {% else %}
  268. {{ render_vhost_directives() }}
  269. {% endif %}
  270. }
  271. {% if matrix_nginx_proxy_https_enabled %}
  272. server {
  273. listen {{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  274. listen [::]:{{ 8443 if matrix_nginx_proxy_enabled else 443 }} ssl http2;
  275. server_name {{ matrix_nginx_proxy_proxy_matrix_hostname }};
  276. server_tokens off;
  277. root /dev/null;
  278. ssl_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/fullchain.pem;
  279. ssl_certificate_key {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/privkey.pem;
  280. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  281. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  282. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  283. {% endif %}
  284. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  285. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  286. ssl_stapling on;
  287. ssl_stapling_verify on;
  288. ssl_trusted_certificate {{ matrix_ssl_config_dir_path }}/live/{{ matrix_nginx_proxy_proxy_matrix_hostname }}/chain.pem;
  289. {% endif %}
  290. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  291. ssl_session_tickets off;
  292. {% endif %}
  293. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  294. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  295. {{ render_vhost_directives() }}
  296. }
  297. {% endif %}
  298. {% if matrix_nginx_proxy_proxy_matrix_federation_api_enabled %}
  299. {#
  300. This federation vhost is a little special.
  301. It serves federation over HTTP or HTTPS, depending on `matrix_nginx_proxy_https_enabled`.
  302. #}
  303. server {
  304. {% if matrix_nginx_proxy_https_enabled %}
  305. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  306. listen [::]:{{ matrix_nginx_proxy_proxy_matrix_federation_port }} ssl http2;
  307. {% else %}
  308. listen {{ matrix_nginx_proxy_proxy_matrix_federation_port }};
  309. {% endif %}
  310. server_name {{ matrix_nginx_proxy_proxy_matrix_federation_hostname }};
  311. server_tokens off;
  312. root /dev/null;
  313. gzip on;
  314. gzip_types text/plain application/json;
  315. {% if matrix_nginx_proxy_https_enabled %}
  316. ssl_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate }};
  317. ssl_certificate_key {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_certificate_key }};
  318. ssl_protocols {{ matrix_nginx_proxy_ssl_protocols }};
  319. {% if matrix_nginx_proxy_ssl_ciphers != '' %}
  320. ssl_ciphers {{ matrix_nginx_proxy_ssl_ciphers }};
  321. {% endif %}
  322. ssl_prefer_server_ciphers {{ matrix_nginx_proxy_ssl_prefer_server_ciphers }};
  323. {% if matrix_nginx_proxy_ocsp_stapling_enabled %}
  324. ssl_stapling on;
  325. ssl_stapling_verify on;
  326. ssl_trusted_certificate {{ matrix_nginx_proxy_proxy_matrix_federation_api_ssl_trusted_certificate }};
  327. {% endif %}
  328. {% if matrix_nginx_proxy_ssl_session_tickets_off %}
  329. ssl_session_tickets off;
  330. {% endif %}
  331. ssl_session_cache {{ matrix_nginx_proxy_ssl_session_cache }};
  332. ssl_session_timeout {{ matrix_nginx_proxy_ssl_session_timeout }};
  333. {% endif %}
  334. location / {
  335. {% if matrix_nginx_proxy_enabled %}
  336. {# Use the embedded DNS resolver in Docker containers to discover the service #}
  337. resolver {{ matrix_nginx_proxy_http_level_resolver }} valid=5s;
  338. set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
  339. proxy_pass http://$backend;
  340. {% else %}
  341. {# Generic configuration for use outside of our container setup #}
  342. proxy_pass http://{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_sans_container }};
  343. {% endif %}
  344. proxy_set_header Host $host;
  345. proxy_set_header X-Forwarded-For {{ matrix_nginx_proxy_x_forwarded_for }};
  346. proxy_set_header X-Forwarded-Proto {{ matrix_nginx_proxy_x_forwarded_proto_value }};
  347. client_body_buffer_size 25M;
  348. client_max_body_size {{ matrix_nginx_proxy_proxy_matrix_federation_api_client_max_body_size_mb }}M;
  349. proxy_max_temp_file_size 0;
  350. }
  351. }
  352. {% endif %}