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.

146 lines
5.9 KiB

  1. # SPDX-FileCopyrightText: 2023 - 2024 Jost Alemann
  2. # SPDX-FileCopyrightText: 2024 - 2025 Suguru Hirahara
  3. # SPDX-FileCopyrightText: 2024 Slavi Pantaleev
  4. #
  5. # SPDX-License-Identifier: AGPL-3.0-or-later
  6. server {
  7. # TODO: once per IP and port you should add `reuseport`, if you don't have that in any other nginx config file, add it here by uncommenting the lines below and commenting the one after with `quic` but without `reuseport`
  8. #listen 443 quic reuseport;
  9. listen 443 quic;
  10. listen 443 ssl;
  11. # TODO: if you replaced the line above for port 443 and IPv4, you probably want to do the same for port 443 IPv6 by switching the two lines below
  12. #listen [::]:443 quic reuseport;
  13. listen [::]:443 quic;
  14. listen [::]:443 ssl;
  15. http2 on;
  16. http3 on;
  17. # TODO: add/remove services and their subdomains if you use/don't use them
  18. # this example is using hosting something on the base domain and an Element Web client, so example.com and element.example.com are listed in addition to matrix.example.com
  19. # if you don't use those, you can remove them
  20. # if you use e.g. Etherpad on etherpad.example.com, add etherpad.example.com to the server_name list
  21. server_name example.com matrix.example.com element.example.com;
  22. # Required for Matrix RTC (WebSocket proxying to LiveKit Server).
  23. # See: ../../../docs/configuring-playbook-matrix-rtc.md#fronting-the-integrated-reverse-proxy-with-another-reverse-proxy
  24. location /livekit-server/ {
  25. proxy_pass http://localhost:81/livekit-server/;
  26. proxy_http_version 1.1;
  27. proxy_set_header Upgrade $http_upgrade;
  28. proxy_set_header Connection "upgrade";
  29. proxy_set_header X-Forwarded-For $remote_addr;
  30. proxy_set_header X-Forwarded-Proto $scheme;
  31. proxy_set_header Host $host;
  32. proxy_set_header X-Real-IP $remote_addr;
  33. # Long timeouts for persistent WebSocket connections
  34. proxy_read_timeout 86400s;
  35. proxy_send_timeout 86400s;
  36. proxy_buffering off;
  37. access_log /var/log/nginx/matrix.access.log;
  38. error_log /var/log/nginx/matrix.error.log;
  39. }
  40. location / {
  41. # note: do not add a path (even a single /) after the port in `proxy_pass`,
  42. # otherwise, nginx will canonicalise the URI and cause signature verification
  43. # errors.
  44. proxy_pass http://localhost:81;
  45. proxy_set_header X-Forwarded-For $remote_addr;
  46. proxy_set_header X-Forwarded-Proto $scheme;
  47. proxy_set_header Host $host;
  48. proxy_set_header X-Real-IP $remote_addr;
  49. access_log /var/log/nginx/matrix.access.log;
  50. error_log /var/log/nginx/matrix.error.log;
  51. # Nginx by default only allows file uploads up to 1M in size
  52. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  53. client_max_body_size 50M;
  54. # required for browsers to direct them to quic port
  55. add_header Alt-Svc 'h3=":443"; ma=86400';
  56. }
  57. # TODO: adapt the path to your ssl certificate for the domains listed on server_name
  58. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  59. # TODO: adapt the path to your ssl certificate for the domains listed on server_name
  60. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  61. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  62. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  63. }
  64. # settings for Matrix federation
  65. server {
  66. # For the federation port
  67. # TODO: once per IP and port you should add `reuseport`, if you don't have that in any other nginx config file, add it here by uncommenting the lines below and commenting the one after with `quic` but without `reuseport`
  68. #listen 8448 quic reuseport;
  69. listen 8448 quic;
  70. listen 8448 ssl default_server;
  71. # TODO: if you replaced the line above for port 8448 and IPv4, you probably want to do the same for port 8448 IPv6 by switching the two lines below
  72. #listen [::]:8448 quic reuseport;
  73. listen [::]:8448 quic;
  74. listen [::]:8448 ssl default_server;
  75. http2 on;
  76. http3 on;
  77. server_name matrix.example.com;
  78. location / {
  79. proxy_pass http://localhost:8449;
  80. proxy_set_header X-Forwarded-For $remote_addr;
  81. proxy_set_header X-Forwarded-Proto $scheme;
  82. proxy_set_header Host $host;
  83. access_log /var/log/nginx/matrix.access.log;
  84. error_log /var/log/nginx/matrix.error.log;
  85. # Nginx by default only allows file uploads up to 1M in size
  86. # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
  87. client_max_body_size 50M;
  88. # required for browsers to direct them to quic port
  89. add_header Alt-Svc 'h3=":8448"; ma=86400';
  90. }
  91. # TODO: adapt the path to your ssl certificate for the domains listed on server_name
  92. ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  93. # TODO: adapt the path to your ssl certificate for the domains listed on server_name
  94. ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  95. include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
  96. ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
  97. }
  98. # ensure using https
  99. # TODO: remove server blocks that you don't use / add server blocks for domains you do use
  100. server {
  101. if ($host = example.com) {
  102. return 301 https://$host$request_uri;
  103. } # managed by Certbot
  104. server_name example.com;
  105. listen 80;
  106. return 404; # managed by Certbot
  107. }
  108. server {
  109. if ($host = matrix.example.com) {
  110. return 301 https://$host$request_uri;
  111. } # managed by Certbot
  112. server_name matrix.example.com;
  113. listen 80;
  114. return 404; # managed by Certbot
  115. }
  116. server {
  117. if ($host = element.example.com) {
  118. return 301 https://$host$request_uri;
  119. } # managed by Certbot
  120. server_name element.example.com;
  121. listen 80;
  122. return 404; # managed by Certbot
  123. }