How to set up a HOOPS Communicator server in AWS with reverse proxy

Introduction

In this article, we’re going to describe setting up a HOOPS Communicator Stream Cache Server using a Ubuntu Server 20.04 EC2 instance with AWS, with Nginx to proxy traffic to the required ports streaming data to a HOOPS Communicator Web Viewer.

Instructions

Create a Ubuntu EC2 instance

  1. Create a Ubuntu Server 20.04 LTS EC2 instance with AWS
  2. Configure HTTP port (80) in the inbound rule of the security group for a TCP connection

  1. Log into the virtual server using an SSH

Ubuntu environment and nginx setup

  1. Install and upgrade necessary packages.
    Update available packages:
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install linux-headers-generic linux-headers-virtual linux-image-virtual linux-virtual

Install required packages:

sudo apt-get install linux-source linux-image-extra-virtual build-essential xserver-xorg mesa-utils libgl1-mesa-glx libglu1-mesa build-essential unzip xinit

Install kernel header package:

sudo apt-get install linux-headers-`uname -r`
  1. Install nginx
sudo apt-get install -y nginx
  1. Open the virtual server’s public IP address in your preferred web browser, and verify the default nginix Welcome page appears.

HOOPS Communicator server installation

Place the folders and files required for the HC server from the HOOPS Communicator SDK.

Here is an illustration of how to configure the server:

img_14

  1. Transfer the tar.gz file of HOOPS Communicator for Linux to the /tmp folder of the virtual server via SCP
  2. Extract the tar.gz file
cd /tmp
tar -zxvf HOOPS_Communicator_202x_SPx_Linux.tar.gz
  1. Create the /HC folder and allocate the necessary folders in it
// Create root directory of HC server
sudo mkdir /HC
sudo mkdir /HC/html

// Copy server and 3rd_party folders
cd HOOPS_Communicator_202x_SPx/
sudo cp -r 3rd_party/ server/ /HC/

// Copy sample SC models
sudo cp -r quick_start/converted_models/standard/sc_models/ /HC/

// Copy Web Viewer src
sudo cp -r web_viewer/src /HC/html/

HOOPS Communicator server setup

  1. Open Config.js for HC Stream Cache Server
sudo vi /HC/server/node/Config.js
  1. Set model search directory
    modelDirs: [
        "./sc_models",
    ],
  1. Save and quit::wq

nginx server settings

  1. Open the nginx config file
sudo vi /etc/nginx/sites-enabled/default
  1. Change the root directory of the HTTP server
        root /HC/html;
  1. Save and quit: :wq
  2. Reload nginx
sudo service nginx reload

Start the HOOPS Communicator server

  1. Edit the inbound rules of the virtual server to open port 11182

  1. Start the HOOPS Communicator server
sudo sh /HC/server/node/start_server.sh

  1. Open http://xxx.xxx.xxx.xxx/src/hoops_web_viewer_sample.html?wsPort=11182&instance=microengine (xxx.xxx.xxx.xxx is your public IP address) using a supported browser to verify you have installed and configured HOOPS Communicator correctly:

Setting reverse proxy

The HC server has now been configured, but there is a non-standard port: 11182
that is open to the internet, posing a security risk. We’ll need to close it by restricting the non-standard port to the private environment. It’s important the user minimizes exposure to the public zone.

  1. Edit the inbound rules of the security group to allow access to the virtual server from only local domains

Replace 172.31.26 with your private IP address

  1. Stop the HOOPS Communicator Server by pressing the Enter key on the SSH
  2. Open the nginx setting file
sudo vi /etc/nginx/sites-enabled/default
  1. Add the following location under existing location / {…} (yyy.yyy.yyy.yyy is your private IP address)
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
        location /wsproxy/ {
            rewrite /wsproxy/([^/]+) / break;
            proxy_pass http://yyy.yyy.yyy.yyy:$1;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
  1. Save and quit: :wq
  2. Reload nginx
sudo service nginx reload

Minimal sample viewer creation

Configure a proxy connection using a minimal HTML sample.

  1. Create a sample HTML and open
sudo touch /HC/html/sample.html
sudo vi /HC/html/sample.html
  1. Implement the following HTML
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Simple</title>
         <style>
            #container {
                width:600px;
                height:480px;
                position:relative;
                border: thin solid #000000;
            }
        </style>	
       
        <script type="text/javascript" src="src/js/hoops_web_viewer.js"></script>
        
        <script type="text/javascript">
            let viewer;
            window.onload = function () {
                const endpoint = "ws://" + window.location.hostname + "/wsproxy/11182";
                viewer = new Communicator.WebViewer({
                    containerId: "container",
                    model: "microengine",
                    endpointUri: endpoint,
                });
                viewer.start();
            };
        </script>
    </head>
    <body>
        <div id="container"></div>
    </body>
</html>
  1. Save and quit::wq
  2. Start the HOOPS Communicator Server
sudo sh /HC/server/node/start_server.sh
  1. Open http://xxx.xxx.xxx.xxx/sample.html (xxx.xxx.xxx.xxx is your public IP address) using your web browser to verify you have configured the proxy connections correctly

Here is an illustration after applying the proxy connections

HC server start service

Make a service so that the HC Server is started at boot time.

  1. Create a description file for service and open
sudo touch /etc/systemd/system/onboot.service
sudo vi /etc/systemd/system/onboot.service
  1. Write the following service description
[Unit]
Description=auto start commands in /etc/onboot.sh on boot
[Service]
Type=simple
ExecStart=/etc/onboot.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
  1. Save and quit::wq
  2. Create a shell file for the service and open
sudo touch /etc/onboot.sh
sudo chmod 0755 /etc/onboot.sh
sudo vi /etc/onboot.sh
  1. Write the following shell command to start the server
#!/bin/bash
sudo sh /HC/server/node/start_server.sh
  1. Save and quit: :wq
  2. Verify the service is registered
sudo systemctl list-unit-files --type=service | grep onboot.service

  1. Enable the service to start automatically
sudo systemctl enable onboot.service
  1. Restart the virtual server and verify whether HOOPS Communicator Server is started automatically
sudo systemctl status onboot.service

  1. Reload the URL of sample the HTML (http://xxx.xxx.xxx.xxx/sample.html) in your web browser to verify you have configured HC Server to automatically start as a service correctly