Matrix Docker Ansible eploy
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

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