Project

General

Profile

Actions

Install Mediasoup API on Ubuntu Bionic

This guide will provide the correct way to deploy mediasoup-api on public server.

Install repository

echo "deb [trusted=yes] https://projects.iabsis.com/repository/mediasoup-api/debian bionic main" \
  > /etc/apt/sources.list.d/iabsis.list

cat > /etc/apt/auth.conf << EOF
machine projects.iabsis.com
login iabsis-apt
password <password>
EOF

chmod 600 /etc/apt/auth.conf
NAME=nodejs
VERSION=10
KEY_URL="https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
APT_URL="deb https://deb.nodesource.com/node_${VERSION}.x $(lsb_release -sc) main"

curl -s ${KEY_URL} | apt-key add -
echo ${APT_URL} > /etc/apt/sources.list.d/${NAME}.list
apt update

Install package

apt update && apt install mediasoup-api nginx

Configure Mediasoup

nano /etc/mediasoup-api/mediasoup-api.conf
## Define random key here
JWT_SECRET=<change secret>

## Configure credentials used to consume mediasoup API
API_USER=<define login>
API_SECRET=<define password>

## Define here the public IP server
PUBLIC_IP=<define local server IP>

## If server is behind nat, you might need to advertise 
# the real public IP by commenting out this line.
;ANNOUNCED_IP=1.2.3.4

## You will need to open UDP port in the follow range, you
# can adjust the range if required.
RTC_MIN_PORT=40000
RTC_MAX_PORT=49000

## If this server is behind a reverse proxy, you might need to trust it
TRUST_PROXY=127.0.0.1

## The best practice is to use reverse proxy, but if you want
# this API to serve directly HTTPS, you might need to configure the
# following lines
HTTP_ONLY=true
LISTEN=3480
;CERT=/etc/mediasoup-api/sample.localhost.cert.pem
;KEY=/etc/mediasoup-api/sample.localhost.key.pem
LISTEN_REDIRECT=3481
nano /usr/share/mediasoup-api/config/config.js

Enable mediasoup at boot

systemctl enable mediasoup-api
systemctl start mediasoup-api

Configure Nginx

cat > /etc/nginx/sites-enabled/mediasoup-api.conf << EOF
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    server_name <domain>;

    location / {
        proxy_set_header Host $host;
        proxy_pass https://localhost:3480;
        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port $server_port;

        proxy_connect_timeout 120m;
        proxy_send_timeout 120m;
        proxy_read_timeout 120m;
    }

    listen 80;

}
EOF

Updated by Olivier Bitsch about 3 years ago · 9 revisions