#!/bin/bash set -euo pipefail apt-get install -y nginx apache2-htpasswd printf 'P@ssw0rd\n' | htpasswd -ci /etc/nginx/kim2027-web.htpasswd WEB chown root:_nginx /etc/nginx/kim2027-web.htpasswd chmod 640 /etc/nginx/kim2027-web.htpasswd cat > /etc/nginx/sites-enabled.d/kim2027.conf <<'EOF' server { listen 172.16.2.1:80; server_name web.au-team.irpo; auth_basic "KIM2027 WEB"; auth_basic_user_file /etc/nginx/kim2027-web.htpasswd; location / { proxy_pass http://172.16.1.2:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } server { listen 172.16.1.1:80; server_name docker.au-team.irpo; location / { proxy_pass http://172.16.2.2:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } EOF nginx -t systemctl enable --now nginx systemctl reload nginx test "$(curl -s -o /dev/null -w '%{http_code}' -H 'Host: web.au-team.irpo' http://172.16.2.1/)" = 401 test "$(curl -s -o /dev/null -w '%{http_code}' -u WEB:wrong -H 'Host: web.au-team.irpo' http://172.16.2.1/)" = 401 curl -fsS -u 'WEB:P@ssw0rd' -H 'Host: web.au-team.irpo' http://172.16.2.1/ | grep DemoTest curl -fsS -H 'Host: docker.au-team.irpo' http://172.16.1.1/ | grep tableBody echo ALL_PROXY_HTTP_AUTH_PROBES_COMPLETED