# matrix.daarion.space — Synapse Matrix Homeserver (Phase M1)
# Active on NODA1 since 2026-03-05
# TLS: Let's Encrypt (auto-renew via certbot cron), expires 2026-06-03

server {
    listen 80;
    listen [::]:80;
    server_name matrix.daarion.space;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
        allow all;
    }

    location / {
        return 301 https://matrix.daarion.space$request_uri;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name matrix.daarion.space;

    ssl_certificate /etc/letsencrypt/live/matrix.daarion.space/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/matrix.daarion.space/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;

    # Matrix file uploads (media, avatars)
    client_max_body_size 50m;

    # Matrix Client-Server API
    location /_matrix {
        proxy_pass http://127.0.0.1:8008;
        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 https;
        proxy_read_timeout 600s;
        proxy_connect_timeout 10s;
    }

    # Synapse admin API
    location /_synapse {
        proxy_pass http://127.0.0.1:8008;
        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 https;
        proxy_read_timeout 600s;
    }

    # Element auto-discovery
    location /.well-known/matrix {
        default_type application/json;
        add_header Access-Control-Allow-Origin *;
        return 200 '{"m.homeserver":{"base_url":"https://matrix.daarion.space"}}';
    }

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
}
