This repository helps you run your messaging application.
You can set up all you need for the matrix in less than an hour. It will install the following applications for you.
- Synapse
 - Element
 - PostgreSQL
 - Coturn
 - Nginx
 - Traefik
 
- Docker
 - Docker-compose
 
- Add these two subdomains to your DNS:
 
matrix.example.com
web.example.com
- Clone the repository and go to the 
matrixdirectory 
- Copy 
.env.exampleto.envand changeDOMAINin.envfile to your domain 
- Run 
docker-compose upand after 1 minute stop it to do the next action. 
- Edit the 
/var/lib/docker/volumes/matrix_nginx_conf/_data/default.confand add these lines in the bottom of the file before}, then change theexample.comto your domain. 
    location /.well-known/matrix/server {
        access_log off;
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
        return 200 '{"m.server": "matrix.example.com:443"}';
    }
    location /.well-known/matrix/client {
        access_log off;
        add_header Access-Control-Allow-Origin *;
        default_type application/json;
        return 200 '{"m.homeserver": {"base_url": "https://matrix.example.com"}}';
    }
- Edit the 
/var/lib/docker/volumes/matrix_coturn/_data/turnserver.confand add the below configuration: 
- Replace the 
LongSecretKeyMustEnterHerewith a secure random password. - Replace 
matrix.example.comwith your domain - Change the 
YourServerIPto your server's public IP address. 
use-auth-secret
static-auth-secret=LongSecretKeyMustEnterHere
realm=matrix.example.com
listening-port=3478
tls-listening-port=5349
min-port=49160
max-port=49200
verbose
allow-loopback-peers
cli-password=SomePasswordForCLI
external-ip=YourServerIP
- Change the 
example.comwith your domain in the below command and run it 
docker run -it --rm -v matrix_synapse_data:/data -e SYNAPSE_SERVER_NAME=example.com -e SYNAPSE_REPORT_STATS=yes matrixdotorg/synapse:latest generate
- Edit 
/var/lib/docker/volumes/matrix_synapse_data/_data/homeserver.yamlfile and change it as below: 
- You need to replace the database config with PostgreSQL
 
Don't worry about the database security, this is not going to be exposed to the internet.
database:
  name: psycopg2
  txn_limit: 10000
  args:
    user: synapse
    password: aComplexPassphraseNobodyCanGuess
    database: synapse
    host: matrix_synapse_db_1
    port: 5432
    cp_min: 5
    cp_max: 10
- Add below configuration to the end of the file
 - Change all 
example.comto your domain address. - Change 
LongSecretKeyMustEnterHereto the secret key that you chose before in/var/lib/docker/volumes/matrix_coturn/_data/turnserver.conf 
turn_uris:
  - "turn:matrix.example.com:3478?transport=udp"
  - "turn:matrix.example.com:3478?transport=tcp"
  - "turns:matrix.example.com:3478?transport=udp"
  - "turns:matrix.example.com:3478?transport=tcp"
turn_shared_secret: "LongSecretKeyMustEnterHere"
turn_user_lifetime: 86400000
turn_allow_guests: False
- Run the containers with 
docker-compose upand if everything goes well, stop them and run thedocker-compose up -dto run these containers in the background. 
- The matrix URL (
https://matrix.example.com) must show the synapse default page - Nginx must respond to these two URLs
 - You can test the federation on the link below
 - You can log in to your Element client at 
https://web.example.com 
Run the below command to create a user.
docker exec -it matrix_synapse_1 register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008
By default, registration is disabled, and users must be added using the command line. If you want to allow
everybody to register in your matrix, you can add the below line to the end of /var/lib/docker/volumes/matrix_synapse_data/_data/homeserver.yaml file.
enable_registration: true
enable_registration_without_verification: true
Run the docker-compose restart to apply the new setting.
If you need to have email verification enabled or a captcha on registration, you can read the link below:
https://www.youtube.com/watch?v=JCsw1bbBjAM
https://matrix.org/docs/guides/understanding-synapse-hosting
