Host your own end-to-end encrypted chat server
Matrix is an open protocol for real-time communication. It provides:
Before anything else, point your domain at your server:
A record → your server IP (e.g., matrix.yourdomain.com)A record → your server IP (e.g., element.yourdomain.com)Wait 5-10 minutes for DNS to propagate.
curl -fsSL https://get.docker.com | sh systemctl enable docker systemctl start docker
mkdir -p ~/matrix
cd ~/matrix
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
synapse:
image: matrixdotorg/synapse:latest
container_name: synapse
restart: unless-stopped
ports:
- "8008:8008"
volumes:
- ./data:/data
environment:
- SYNAPSE_SERVER_NAME=matrix.yourdomain.com
- SYNAPSE_REPORT_STATS=no
element:
image: vectorized/element-web:latest
container_name: element
restart: unless-stopped
ports:
- "8080:80"
volumes:
- ./element-config.json:/etc/element/config.json:ro
volumes:
data:
EOF
# Create config directory mkdir -p ~/matrix/data # Generate config (replace with your domain) docker run -it --rm -v ~/matrix/data:/data -e SYNAPSE_SERVER_NAME=matrix.yourdomain.com matrixdotorg/synapse generate
# Install certbot apt install certbot python3-certbot-nginx # Get certificate (stop nginx first if running) certbot certonly --standalone -d matrix.yourdomain.com # Copy certificates cp /etc/letsencrypt/live-matrix.yourdomain.com/fullchain.pem ~/matrix/data/ cp /etc/letsencrypt/live-matrix.yourdomain.com/privkey.pem ~/matrix/data/
cat > ~/matrix/element-config.json << 'EOF'
{
"default_server_name": "matrix.yourdomain.com",
"default_server_url": "https://matrix.yourdomain.com"
}
EOF
cat > /etc/nginx/sites-available/matrix << 'EOF'
server {
listen 443 ssl http2;
server_name matrix.yourdomain.com;
ssl_certificate /etc/letsencrypt/live-matrix.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live-matrix.yourdomain.com/privkey.pem;
location / {
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;
}
}
server {
listen 443 ssl http2;
server_name element.yourdomain.com;
ssl_certificate /etc/letsencrypt/live-matrix.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live-matrix.yourdomain.com/privkey.pem;
location / {
proxy_pass http://localhost:8080;
}
}
EOF
ln -s /etc/nginx/sites-available/matrix /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
cd ~/matrix docker-compose up -d docker-compose logs -f
docker exec -it synapse register_new_matrix_user -u admin -p YourPassword -a http://localhost:8008
Access Element web client at https://element.yourdomain.com
Log in with your admin credentials or create new users.
For mobile, download Element from F-Droid or App Store and enter your server URL.
Matrix can bridge to other chat platforms. Here are popular bridges:
"The right to privacy is essential to the right to freedom of speech. Matrix gives you that privacy by default." — The Rebel