LINUX.ORG.RU
ФорумAdmin

Правильная настройка well-known для matrix-synapse

 , ,


1

2

Настраиваю well-known для example.com, размещая сам matrix-synapse на subdomain.example.com. Суть проблемы: не могу написать кому-то на другом сервере, как и мне с другого сервера не могут написать и даже найти мой аккаунт. В свой аккаунт на сервере я могу войти. Порты федерации не закрыты.

Прилагаю конфиги:

example.com:

server {
    listen 80;
        listen [::]:80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name example.com;
   # root /var/www/matrix/html;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location /.well-known/matrix/server {
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
       # try_files /var/www/matrix/html/.well-known/matrix/server =404;
        return 200 '{"m.server": "subdomain.example.com:8448"}';
    }

    location /.well-known/matrix/client {
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
       # try_files /var/www/matrix/html/.well-known/matrix/client =404;
        return 200 '{"m.homeserver": {"base_url": "https://subdomain.example.com"}}';
    }
}

subdomain.example.com

server {
    listen 80;
        listen [::]:80;
    server_name subdomain.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    http2 on;
    server_name subdomain.example.com;

    ssl_certificate /etc/letsencrypt/live/subdomain.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/subdomain.example.com/privkey.pem;

    location ~ ^(/|/_matrix|/_synapse/client) {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $host;
        client_max_body_size 100M;
        proxy_http_version 1.1;
    }
}

server {
    listen 8448 ssl default_server;
    listen [::]:8448 ssl default_server;
    http2 on;
    server_name subdomain.example.com;

    ssl_certificate /etc/letsencrypt/live/subdomain.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/subdomain.example.com/privkey.pem;
    location / {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}

При запросе: curl -I https://example.com/.well-known/matrix/server:

HTTP/2 200
server: nginx
date: Wed, 10 Dec 2025 15:37:21 GMT
content-type: application/json
content-length: 39
access-control-allow-origin: *

Подскажите пожалуйста, что я делаю не правильно? Указывал и файлами в каталоге, но они при curl выдавали content-type: text/html а не json. Файлы без расширений, само собой были. Не то что бы это сильно страшно, я могу использовать и subdomain.example.com, но все же если возможность есть, то почему нет. По SRV записям, насколько я понял, их не все понимают и лучше указывать файлами well-known

★★★

Последнее исправление: Riniko (всего исправлений: 1)

Добавил в subdomain.example.com:

 location ~ ^(/|/_matrix|/_synapse/client) {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Port $server_port;

        proxy_set_header Connection "";
        proxy_set_header Upgrade $http_upgrade;
       # proxy_set_header Connection $connection_upgrade;
        client_max_body_size 100M;
        proxy_http_version 1.1;

location / {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Port $server_port;

        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Upgrade $http_upgrade;
       # proxy_set_header Connection $connection_upgrade;
    }

Результата нет.

Riniko ★★★
() автор топика

У меня в nginx для example.org

    location /.well-known/matrix/server {
        default_type application/json;
        add_header Access-Control-Allow-Origin *;
        return 200
'{
    "m.server": "matrix.example.org:443"
}';
    }

    location /.well-known/matrix/client {
        default_type application/json;
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
        add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Authorization';
        return 200
'{
    "m.homeserver": {
        "base_url": "https://matrix.example.org"
    },
    "im.vector.riot.jitsi": {
        "preferredDomain": "meet.example.org"
    },
    "io.element.jitsi": {
        "preferredDomain": "meet.example.org"
    },
}';
    }

И кстати отдельный порт для федерации не обязателен, можно всё через 443 гнать. Имей в виду что как минимум клиенты любят (как минимум Element десктопный) намертво кэшировать well-known и долбиться по старому адресу до упора

MrClon ★★★★★
()
Ответ на: комментарий от MrClon

Конфиг matrix.example.org.

server {
    listen 80; ## listen for ipv4; this line is default and implied
    listen 443 ssl http2;

    root /var/www/matrix.example.org/webroot;
    index index.php index.html index.htm;

    server_name matrix.example.org www.matrix.example.org;

    ssl_certificate /var/www/matrix.example.org/letsencrypt/certs/matrix.example.org/fullchain.pem;
    ssl_certificate_key /var/www/matrix.example.org/letsencrypt/certs/matrix.example.org/privkey.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_session_cache   shared:SSL:10m;

    access_log /var/log/nginx/matrix.example.org-access.log;
    error_log /var/log/nginx/matrix.example.org-error.log;

    location ~ ^(/_matrix|/_synapse/client) {
        # note: do not add a path (even a single /) after the port in `proxy_pass`,
        # otherwise nginx will canonicalise the URI and cause signature verification
        # errors.
        proxy_pass http://192.168.0.2:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;

        # Nginx by default only allows file uploads up to 1M in size
        # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
        client_max_body_size 50M;
    
        # Synapse responses may be chunked, which is an HTTP/1.1 feature.
        proxy_http_version 1.1;
    }

    location /.well-known/acme-challenge {
        alias /var/www/matrix.example.org/letsencrypt/well-known/acme-challenges;
    }
}

приведённые выше В example.org то же самое, плюс well-known (приходится держать проксирование по старому адресу ради закешировавших его клиентов, может уже можно убрать, ХЗ)

MrClon ★★★★★
()