Skip to content

Install Mercure hub for realtime communication (SSE) This is necessary for the new lobby function

holema edited this page Mar 20, 2022 · 7 revisions

Install Mercure for jitsi-admin

Download binary

First the mercure hub has to be downloaded and installed as described. Fot this, follow the instruction on the mercure rocks page: https://mercure.rocks/docs/hub/install You get the latest binary from here: https://github.com/dunglas/mercure/releases

take your package from the release page and download it into /bin/mercure directory extract the tar file with tar -xf mercure_0.13.0_Linux_x86_64.tar.gz

example for debian

cd /bin/
mkdir mercure
wget https://github.com/dunglas/mercure/releases/download/v0.13.0/mercure_0.13.0_Linux_x86_64.tar.gz
tar -xf mercure_0.13.0_Linux_x86_64.tar.gz

The mercure must be configured. This is a sample config which is located in the etc/mercure/Caddyfile file

# etc/mercure/Caddyfile
{
    auto_https off
    log {
        output file /var/log/mercure/mercure_access_prod.log {
            level ERROR
            roll_size 10mb
            roll_keep 3
            roll_keep_for 720h
        }
    }
}

{

	{$GLOBAL_OPTIONS}
}

{$SERVER_NAME:localhost}


route {
	encode zstd gzip

	mercure {
		# Transport to use (default to Bolt)
		transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db}
		# Publisher JWT key
		publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
		# Subscriber JWT key
		subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
		# Permissive configuration for the development environment
		anonymous
		# Extra directives
		{$MERCURE_EXTRA_DIRECTIVES}
	}

	respond /healthz 200

	respond "Not Found" 404
}

Create mercure service

We recommend to crate a systemd file to restart the mercure service automaticals on server restart. Sample Config for mercure.service

#/etc/systemd/system/mercure.service
[Unit]
     Description=Mercure.Rocks service
     After=network.target
     StartLimitBurst=5
     StartLimitIntervalSec=33


     [Service]
     Type=simple
     WorkingDirectory=/bin/mercure
    
	Environment= MERCURE_PUBLISHER_JWT_KEY='secret_jwt_goes_here' MERCURE_SUBSCRIBER_JWT_KEY='secret_jwt_goes_here' SERVER_NAME=':3000'
     ExecStart=/bin/mercure/mercure run -config /etc/mercure/Caddyfile
     StandardOutput=file:/var/log/mercure.log
     StandardError=file:/var/log/mercure.log
     Restart=always
     RestartSec=5

     [Install]
     WantedBy=multi-user.target

To reload the daemon and restart the mercure daemon

systemctl daemon-reload
systemctl enable mercure.service
systemctl start mercure.service
systemctl restart mercure.service

The jwt secret which is added here in the service must be the same as the JWT key in the env.local file MERCURE_JWT_SECRET=secret_jwt_goes_here

Config apache as reverse proxy to listen for port 3000

normaly the mercure hub listen on tpc:3000 port for the clients to connect to. To prevent to many open porty on the server, here it is necessary to forward a request to the apache webserver to the mercure-hub.

for this we activate the apache reverse proxy module:

a2enmod proxy and a2enmod http_proxy and a2enmod proxy_balance

to setup the reverse route the following part has to be added in you apache config file:

<VirtualHost *:443>
.......
here comes the normal jitsi-admin config
</VirtualHost>

ProxyPass /.well-known  http://127.0.0.1:3000/.well-known/mercure
ProxyPassReverse /.well-known http://127.0.0.1:3000/.well-known/mercure
ProxyPass /healthz http://127.0.0.1:3000/healthz
ProxyPassReverse /healthz  http://127.0.0.1:3000/healthz

After this the mercure hub is recieving http-requests via the apache reverse proxy. to check the mercure is working and the apache is configured correctly, go to http(s)://<serverUrl>/healthz there mus be a white page shown and no 404 error from the jitsi-admin.

Config Jitsi-Admin to work with the mercure hub

Add the jitsi-admin url in your local .env.local file:

MERCURE_URL=<here goes your domain>/.well-known/mercure
MERCURE_JWT_SECRET=secret_jwt_goes_here