HTTP Basic Auth применяйте только поверх HTTPS. Пароли храните вне document root в htpasswd-файле с минимальными правами.
Важно: Basic Auth передаёт пароль в обратимо кодируемом виде внутри TLS. Без HTTPS использовать нельзя.
1. Установите утилиту
sudo apt update
sudo apt full-upgrade -y
sudo apt install -y apache2-utils
2. Создайте файл паролей
sudo install -d -m 0750 -o root -g www-data /etc/nginx/auth
sudo htpasswd -cB /etc/nginx/auth/users admin
sudo chown root:www-data /etc/nginx/auth/users
sudo chmod 0640 /etc/nginx/auth/users
3. Добавьте в Apache Directory/Location
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/nginx/auth/users
Require valid-user
4. Проверьте и reload
sudo apache2ctl configtest
sudo systemctl reload apache2
curl -I https://example.com/private/
curl -u admin https://example.com/private/