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
- Create a Ubuntu Server 20.04 LTS EC2 instance with AWS
- Configure HTTP port (80) in the inbound rule of the security group for a TCP connection
- Log into the virtual server using an SSH
Ubuntu environment and nginx setup
- 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`
- Install nginx
sudo apt-get install -y nginx
- 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:
- Transfer the
tar.gz
file of HOOPS Communicator for Linux to the/tmp
folder of the virtual server via SCP - Extract the
tar.gz
file
cd /tmp
tar -zxvf HOOPS_Communicator_202x_SPx_Linux.tar.gz
- 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
- Open
Config.js
for HC Stream Cache Server
sudo vi /HC/server/node/Config.js
- Set model search directory
modelDirs: [
"./sc_models",
],
- Save and quit:
:wq
nginx server settings
- Open the nginx config file
sudo vi /etc/nginx/sites-enabled/default
- Change the root directory of the HTTP server
root /HC/html;
- Save and quit:
:wq
- Reload nginx
sudo service nginx reload
Start the HOOPS Communicator server
- Edit the inbound rules of the virtual server to open port 11182
- Start the HOOPS Communicator server
sudo sh /HC/server/node/start_server.sh
- 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.
- 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
- Stop the HOOPS Communicator Server by pressing the
Enter
key on the SSH - Open the nginx setting file
sudo vi /etc/nginx/sites-enabled/default
- 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";
}
- Save and quit:
:wq
- Reload nginx
sudo service nginx reload
Minimal sample viewer creation
Configure a proxy connection using a minimal HTML sample.
- Create a sample HTML and open
sudo touch /HC/html/sample.html
sudo vi /HC/html/sample.html
- 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>
- Save and quit:
:wq
- Start the HOOPS Communicator Server
sudo sh /HC/server/node/start_server.sh
- 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.
- Create a description file for service and open
sudo touch /etc/systemd/system/onboot.service
sudo vi /etc/systemd/system/onboot.service
- 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
- Save and quit:
:wq
- 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
- Write the following shell command to start the server
#!/bin/bash
sudo sh /HC/server/node/start_server.sh
- Save and quit:
:wq
- Verify the service is registered
sudo systemctl list-unit-files --type=service | grep onboot.service
- Enable the service to start automatically
sudo systemctl enable onboot.service
- Restart the virtual server and verify whether HOOPS Communicator Server is started automatically
sudo systemctl status onboot.service
- 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