0

We've set up a Matrix-Synapse chat server at the root of one domain, and we'd like to redirect the /element subdirectory to the Element client hosted at another domain, but without changing the browser's URL.

We've previously used an nginx configuration like this to achieve it, but for some reason it's not working with this setup. The redirect works, but it's changing the browser URL. Here's the nginx config file on the Matrix domain; example.matrix is the Matrix server's domain, example.element is the Element client's domain.

upstream element {
    server example.element;
}

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

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.matrix;

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

    location /element/ {
        proxy_pass http://element/;
        proxy_set_header Host $host;
    }

    location / {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
    }
}

server {
    listen 8448 ssl default_server;
    listen [::]:8448 ssl default_server;
    server_name example.matrix;
 
    ssl_certificate /etc/letsencrypt/live/example.matrix/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.matrix/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 50M;
    }
}

Can anyone spot what we're missing in this config?

  • Have you set the root URL properly in the chat server? – Tero Kilkanen Dec 27 '22 at 23:37
  • Yes, we tried setting the root path and it had no effect. Also tried setting the proxy_pass to ```https://element/``` (instead of http:), still no effect. – Charles Johnson Dec 30 '22 at 19:22
  • What is the chat server and what was the setting name for root URL there that you set? – Tero Kilkanen Dec 31 '22 at 11:10
  • It's the Matrix-Synapse server - our nginx config follows their recommendation from this page: https://matrix-org.github.io/synapse/latest/reverse_proxy.html They don't specify a root, probably because port 443 is being forwarded. Browsing to the domain root shows a dynamically generated page. – Charles Johnson Dec 31 '22 at 19:28
  • Actually I didn't see the question clearly in the first read. You need to check the root URL setting in the Element application here. – Tero Kilkanen Jan 03 '23 at 11:22

0 Answers0