Basic Nginx Auth for Linux HT

Deploying New Nginx Server as Proxy

To enable basic HTTP authentication on you HyperTest Dashboard, we will deploy a Nginx Proxy in front of it.

Here we cannot the Nginx shipped with HyperTest as the configuration for that one gets overridden while upgrading HyperTest.

Here we are deploying one Nginx server which will run as docker container. The requests coming to Nginx server (running on port 8003) will be forwarded to your HyperTest Dashboard

Create a folder nginx-proxy

mkdir /opt/nginx-proxy
cd /opt/nginx-proxy

1. Create password files

We will use openssl to create password file Verify if you have openssl installed by following command

openssl version

If not, install it using below command

sudo apt install openssl
openssl version

Execute the below command to create password files on your host machine where HT is installed

sudo sh -c "echo -n 'HyperTest:' >> .htpasswd"
sudo sh -c "openssl passwd -apr1 >> .htpasswd

Enter the password for "HyperTest" username. It will create a file .htpasswd in current directory

Now we will mount this file in our nginx docker container and reference the file in location blocks in nginx.conf wherever we want authentication.

2. Create docker-compose file

Create the file docker-compose.yml with below contents in it

docker-compose.yml
version: "3.7"

services:
  nginx:
    image: nginx:alpine
    container_name: external_nginx
    volumes:
      - ./.htpasswd:/etc/nginx/.htpasswd:ro
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    network_mode: host
    restart: always

3. Create nginx.conf file

Create the below file nginx.conf with below contents in it

Change the post from 8003 in below nginx.conf if you want to use another port for authenticated HT dashboard

nginx.conf
upstream hypertest-dashboard {
  server <hypertest-vm-ip>:<dashboard-port>;
}

server {
  listen 8003;
  client_max_body_size 600M;

  access_log off;
  	
  location / {
    auth_basic "Authentication Required";
    auth_basic_user_file /etc/nginx/.htpasswd;
    
    proxy_pass http://hypertest-dashboard;
    proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
    proxy_ssl_server_name on;
    proxy_ssl_name $host;
  }
  
  location /portainer {
    proxy_pass http://hypertest-dashboard/portainer;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
  }

  location /portainer/api {
    proxy_set_header Upgrade $http_upgrade;
    proxy_pass http://hypertest-dashboard/portainer/api;
    proxy_set_header Connection 'upgrade';
    proxy_http_version 1.1;
  }

} 

Start the Nginx server using below command:

docker-compose -f docker-compose.yml up -d

Now Nginx server should be up and running, you can check it using below command:

docker ps| grep nginx

To Verify the nginx setup, open the dashboard on http://<hypertest-vm-ip>:8003, it should redirect you to your original HT dahsboard.

Last updated