Skip to content

Instantly share code, notes, and snippets.

@darmawan01
Last active June 5, 2023 05:28
Show Gist options
  • Save darmawan01/bea79b7ef8d155e0f9eefe8dd1b43807 to your computer and use it in GitHub Desktop.
Save darmawan01/bea79b7ef8d155e0f9eefe8dd1b43807 to your computer and use it in GitHub Desktop.
Matrix Synapse
version: '3'
networks:
synapse:
driver: bridge
services:
certbot:
image: certbot/certbot
command: certonly --webroot --webroot-path=/var/www/html --email [email protected] --agree-tos --no-eff-email -d my-domain.com
volumes:
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/html
networks:
- synapse
nginx:
image: nginx
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./certbot/conf:/etc/letsencrypt
- ./certbot/www:/var/www/html
networks:
- synapse
synapse-generate:
image: matrixdotorg/synapse:latest
command: generate
environment:
SYNAPSE_SERVER_NAME: 'my.matrix.host'
SYNAPSE_REPORT_STATS: 'yes'
volumes:
- ./synapse-data:/data
networks:
- synapse
synapse:
image: matrixdotorg/synapse:latest
restart: always
volumes:
- ./synapse-data:/data
ports:
- 8008:8008
depends_on:
- synapse-generate
networks:
- synapse
volumes:
synapse-data:
driver: local
@darmawan01
Copy link
Author

NGINX Config

Put in ./nginx/conf.d/default.confg

server {
    listen 80;
    server_name my-domain.com;

    location / {
        return 301 https://$host$request_uri;
    }
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # For the federation port
    listen 8448 ssl http2 default_server;
    listen [::]:8448 ssl http2 default_server;

    ssl_certificate /etc/letsencrypt/live/my-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/my-domain.com/privkey.pem;

    server_name my-domain.com;

    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://synapse:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        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;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment