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?