Files
fpov/roles/nginx-proxy/templates/default.conf.j2

93 lines
2.6 KiB
Django/Jinja

# Redirect HTTP → HTTPS (except ACME challenges)
server {
listen 80;
server_name {{ matrix_domain }} {{ landing_domain }};
# ACME-challenge (for Let's Encrypt)
location ~ /.well-known/acme-challenge/ {
root /var/www;
try_files $uri =404;
}
location / {
return 301 https://$host$request_uri;
}
}
# HTTPS server
server {
listen 443 ssl http2;
server_name {{ matrix_domain }};
# TLS certs (mounted from Let's Encrypt dir)
ssl_certificate /etc/letsencrypt/live/{{ matrix_domain }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ matrix_domain }}/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/{{ matrix_domain }}/chain.pem;
ssl_session_cache shared:SSL:10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
# Serve static site (root)
location / {
root /usr/share/nginx/html/mysite;
try_files $uri $uri/ /index.html;
}
# Matrix Synapse (client)
location /_matrix/ {
proxy_pass http://127.0.0.1:8008/_matrix/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
# Federation
location /_matrix/federation/v1/ {
proxy_pass http://127.0.0.1:8448/_matrix/federation/v1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Optional: Add a Matrix admin link
location /admin {
return 301 https://matrix-admin.example.com; # or proxy to a UI like SynapseAdmin
}
}
#--- Coturn changes --- #
# TURN over TLS (port 443) — proxied to Coturn's 5349
# Only needed if you want TURN on 443 (avoids firewall issues)
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream coturn_tls {
server 127.0.0.1:5349;
}
server {
listen 443 ssl http2;
server_name {{ matrix_domain }};
# ... [existing TLS config] ...
# TURN over TLS (for UDP/TCP fallback on port 443)
location /turn {
proxy_pass https://coturn_tls;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_read_timeout 86400;
}
# Or simpler: proxy UDP via a dedicated TCP tunnel (advanced)
# For most cases, just expose 3478/5349 directly → no Nginx needed!
}