How to Set Up a HOOPS Visualize Web Server on AWS with a Reverse Proxy

Introduction

In this article, we’ll describe how to set up a HOOPS Visualize Web Stream Cache Server on an Ubuntu Server 24.04 EC2 instance in AWS, using Nginx as a proxy traffic to the required ports for streaming data to the HOOPS Visualize Web Web Viewer.

Instructions

Create an Ubuntu EC2 instance

  1. Create an Ubuntu Server 24.04 LTS EC2 instance in AWS.

  2. Configure the security group inbound rules to allow TCP connections on HTTP port 80.

  3. Log in to the EC2 instance using SSH.

Ubuntu environment and Nginx setup

  1. Install and upgrade the required packages.

    # Update the package list and upgrade installed packages
    sudo apt-get update && sudo apt-get upgrade -y
    
    # Install the required system packages
    sudo apt-get install -y \
        linux-headers-generic \
        linux-headers-virtual \
        linux-image-virtual \
        linux-virtual
    
    # Install additional required packages
    sudo apt-get install -y \
        linux-source \
        linux-image-extra-virtual \
        build-essential \
        xserver-xorg \
        mesa-utils \
        libgl1 \
        libglu1-mesa \
        unzip \
        xinit
    
    # Install the kernel header package for the current kernel version
    sudo apt-get install -y linux-headers-$(uname -r)
    
  2. Install Nginx

    sudo apt-get install -y nginx
    
  3. Open the virtual server’s public IP address in your preferred web browser and verify that the default Nginx welcome page appears.

HOOPS Visualize Web Server installation

Copy the folders and files required for the HOOPS Web server from the HOOPS Visualize Web SDK.

The following example illustrates how to configure the server environment.

var/
 └── www/
      ├── html/
      │    ├── demo-app/
      │    ├── hoops-web-viewer.mjs
      │    ├── engine.esm.wasm
      │    └── sample.html
      ├── server/
      ├── 3rd_party/
      └── sc_models/
  1. Transfer the HOOPS Visualize Web for Linux tar.gz package to the /tmp directory on the virtual server using SCP.

  2. Extract the tar.gz package.

    cd /tmp
    tar -zxvf HOOPS_Visualize_Web_202x.x.x_Linux_x86-64.tar.gz
    
  3. Copy the required files.

    # Move to the extracted SDK directory
    cd HOOPS_Visualize_Web_202x.x.x/
    
    # Copy the server and third-party folders
    sudo cp -r 3rd_party/ server/ /var/www/
    
    # Copy sample Stream Cache models
    sudo cp -r quick_start/converted_models/standard/sc_models/ /var/www/
    
    # Copy the Web Viewer source files
    cd web_viewer/
    sudo cp -r demo-app hoops-web-viewer.mjs engine.esm.wasm /var/www/html/
    

HOOPS Visualize Web server setup

  1. Open the Config.js file for the HOOPS Visualize Web Stream Cache Server.

    sudo vi /var/www/server/node/Config.js
    
  2. Configure the model search directory.

        modelDirs: [
            "./sc_models",
        ],
    
  3. Save the file and exit the editor.

    :wq
    

Add the .mjs Extension to the Nginx MIME Types

Since the .mjs extension is not included in the default Nginx MIME type configuration, you must add it manually.

  1. Open the MIME types configuration file.

    sudo vi /etc/nginx/mime.types
    
  2. Add the mjs extension to the JavaScript MIME type entry.

    Change:

    application/javascript  js;
    

    To:

    application/javascript  js mjs;
    
  3. Save the file and exit the editor.

    :wq
    
  4. Restart Nginx to apply the changes.

    sudo systemctl restart nginx
    

    If the .mjs MIME type is not configured correctly, loading hoops-web-viewer.mjs may result in the following error:
    "Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “application/octet-stream”.

Edit inbound rules

  1. Edit the security group inbound rules for the EC2 instance to allow TCP connections on port 11182.

Start the HOOPS Visualize Web server

  1. Start the HOOPS Visualize Web server.

    cd /var/www/server/node
    ../../3rd_party/node/bin/node --expose-gc ./lib/Startup.js
    

  2. Open http://xxx.xxx.xxx.xxx/demo-app/index.html?wsPort=11182&instance=microengine (xxx.xxx.xxx.xxx is virtual server’s public IP address) using a supported browser to verify you have installed and configured HOOPS Visualize Web correctly:

Setting reverse proxy

The HOOPS Visualize Web server is now configured. However, the non-standard port 11182 is still exposed to the internet, which may pose a security risk.

To improve security, remove the non-standard port 11182 from the security group inbound rules so that it is no longer publicly accessible. Minimizing exposure to the public internet is strongly recommended.

  1. Remove port 11182 from the allowed inbound rules in the security group.

    If you reload the web browser, the following error appears because port 11182 is no longer publicly accessible:
    “Unable to load ‘microengine’: WebSocket connection failed.”

  2. Stop the HOOPS Visualize Web Server by pressing the Enter key in the SSH terminal.

  3. Open the Nginx configuration file.

    sudo vi /etc/nginx/sites-enabled/default
    
  4. Add the following location block below the existing location / { ... } block.

            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://127.0.0.1:$1;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
            }
    
  5. Save the file and exit the editor.

    :wq
    
  6. Reload the Nginx configuration.

    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
    
  2. 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>
    
  3. Save the file and exit the editor.

    :wq
    
  4. Start the HOOPS Visualize Web Server

    cd /var/www/server/node
    ../../3rd_party/node/bin/node --expose-gc ./lib/Startup.js
    
  5. Open http://xxx.xxx.xxx.xxx/sample.html using your web browser to verify you have configured the proxy connections correctly

Here is an illustration after applying the proxy connections

Configure the HOOPS Visualize Web Server to Start Automatically

Create a systemd service so that the HOOPS Visualize Web Server starts automatically when the system boots.

  1. Create and open the service definition file.

    sudo touch /etc/systemd/system/onboot.service
    sudo vi /etc/systemd/system/onboot.service
    
  2. Add the following service configuration.

    [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
    
  3. Save the file and exit the editor.

    :wq
    
  4. Create and open the startup shell script.

    sudo touch /etc/onboot.sh
    sudo chmod 0755 /etc/onboot.sh
    sudo vi /etc/onboot.sh
    
  5. Add the following startup command.

    #!/bin/bash
    cd /var/www/server/node
    ../../3rd_party/node/bin/node --expose-gc ./lib/Startup.js
    
  6. Save the file and exit the editor.

    :wq
    
  7. Verify that the service has been registered correctly.

    sudo systemctl list-unit-files --type=service | grep onboot.service
    

  8. Enable the service to start automatically at boot time.

    sudo systemctl enable onboot.service
    
  9. Restart the virtual server and verify that the HOOPS Visualize Web Server starts automatically.

    sudo systemctl status onboot.service
    

  10. Reload the sample HTML page in your web browser to verify that the HOOPS Visualize Web Server starts correctly as a service.