Basic Janus Configuration with SSL Enabled

Written by: Bagus Facsi Aginsa
Published at: 03 Sep 2021


This tutorial will explain how to do a fresh janus configuration , and as a bonus, we will activate the janus demo page and activate the plugin demo (Echo Test).

Prerequisite

  1. Ubuntu 18.04
  2. SSL Certificate & Key
  3. Janus Installed, you can read this tutorial to help you install janus: How to Install Janus WebRTC Server on Ubuntu 18.04

Sudo Privileges

Before start we make sure that we will have no permission issue on the configuration.

sudo su

The Architecture

In this tutorial, we will use an Nginx to serve external traffic, terminate SSL, and then pass it to Janus via localhost.

                 _______________________________
                |           server              |
                |_________           _________  |
                |         |  http/  |         | |
  https/wss     |  nginx  |   ws    |  janus  | |
------------->  |         | ------> |         | |
                |_________|         |_________| |
                |                               |
                |_______________________________|

Janus HTTP Transport Configuration

Open the HTTP Transport configuration file:

nano /opt/janus/etc/janus/janus.transport.http.jcfg

We can keep most of the configuration to default. We will only change the ip configuration inside general configuration block. Uncomment it and set this to 127.0.0.1. Later we will use Nginx Reverse proxy to receive external traffic and pass them to janus locally.

Keep the https configuration default to false, we will terminate the SSL in the Nginx instead of Janus.

Restart janus

service janus restart

Janus Websocket Transport Configuration

Open the Websocket Transport Configuration file:

nano /opt/janus/etc/janus/janus.transport.websockets.jcfg

Same as http transport configuration, we can keep most of the configuration to default. We will only change the ws_ip configuration inside general configuration block. Uncomment it and set this to 127.0.0.1.

And yes, keep the wss to false.

Restart janus

service janus restart

Nginx Reverse Proxy

If you dont have nginx in your server, just run this command to install Nginx:

apt update
apt install nginx

After nginx installed, create new configuration file

nano /etc/nginx/sites-available/janus

copy and paste this configuration to create new server block

server {
    listen 443 ssl http2;
    server_name <your.domain.com>;  <-- update this line

    ssl_certificate /your/cert/path.crt;  <-- update this line
    ssl_certificate_key /your/key/path.key; <-- update this line

    location /janus {
            proxy_set_header Host $host;
            proxy_set_header Connection "";
            proxy_http_version 1.1;

            proxy_pass http://127.0.0.1:8088;
    }

    location / {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8188;
    }
}

Don’t forget to change the <your.domain.com> and your SSL certificate & key path. Exit & Save.

And then create link and reload NGINX

ln -s /etc/nginx/sites-available/janus /etc/nginx/sites-enabled/
nginx -t
service nginx reload

To check weather the http endpoint is working, open you browser and open this url

https://<your.domain.com>/janus/info

You should get janus server information.

To check weather the websocket endpoint is working, open you browser and open this url

https://<your.domain.com>

If you get 403 message, that mean your configuration is right.

Configure Janus Behind NAT

If your Janus is located behind NAT, then there is additional configuration you must do. You can read this tutorial for configure Janus behind NAT: How to Configure Janus Behind NAT

Activate the Janus Demo Page

To activate the Janus Demo Page, you can add another server block in the Nginx janus configuration. Open the Nginx server configuration

nano /etc/nginx/sites-available/janus

Add this server block on the bottom

server {
    listen 443 ssl http2;
    server_name <another.domain.com>;  <-- update this line

    ssl_certificate /your/cert/path.crt;  <-- update this line
    ssl_certificate_key /your/key/path.key; <-- update this line

    root /opt/janus/share/janus/demos;

    location / {
            index index.html;
            try_files $uri $uri/ index.html 404;
    }
}

Don’t forget to change the <another.domain.com> and your SSL certificate & key path. Exit & Save.

Yes you should configure demo page with different domain if you want both demo page & janus api to both listen on port 443. Alternatively, you can set different listen port, if you want to use the same domain for both demo page & janus api.

Right Now, You can visit <another.domain.com> and see the janus demo page. But we still not done yet. If you want to use the plugin demo like Echo Test, Video Room, etc, there is something you should change in the javascript file.

Activate the Janus Plugin Demo

If you open the demo page, you can click to Demos menu and see the list of plugin demo there. In this tutorial we will activate one of the plugin that is Echo Test plugin.

Open the Echo Test plugin javascript file

nano /opt/janus/share/janus/demos/echotest.js

Find this code:

var server = null;
if(window.location.protocol === 'http:')
        server = "http://" + window.location.hostname + ":8088/janus";
else
        server = "https://" + window.location.hostname + ":8089/janus";

Comment them all and change them to this:

// var server = null;
// if(window.location.protocol === 'http:')
//        server = "http://" + window.location.hostname + ":8088/janus";
// else
//        server = "https://" + window.location.hostname + ":8089/janus";

var server = "wss://<your.domain.com>";

Change the <your.domain.com> to match your janus api domain. And thats it! Now you can try open and use the Echo Test plugin from Demos menu on the demo page.

You can activate another plugin demos by following the same step.

  • To activate Video Room plugin, change the videoroomtest.js file.
  • To activate Video Call plugin, change the videocalltest.js file.
  • To activate Streaming plugin, change the streamingtest.js file.
  • And so on..

Congratulation! You now have configure Janus with SSL Enabled. Later I will make another tutorial how to use Janus API, but right now, you can visit janus documentation page here: https://janus.conf.meetecho.com/docs/pages.html.