How To Set Up Password Authentication with Apache

preview_player
Показать описание
As a web administrator, you may find it valuable to restrict some parts of a website from visitors, whether temporarily or on a permanent basis. While web applications may provide their own authentication and authorization methods, you can also rely on the web server itself to restrict access if these are inadequate or unavailable.

This tutorial will walk you through password-protecting assets on an Apache web server running on Ubuntu 20.04. This will provide your server with an extra layer of security.

Commands used
sudo apt install apache2-utils
sudo htpasswd -c /etc/apache2/.htpasswd user
cat /etc/apache2/.htpasswd

Write to the file

VirtualHost *:80
ServerName your_domain
DocumentRoot /var/www/your_domain

Directory "/var/www/your_domain"
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
/Directory
/VirtualHost

END

sudo apache2ctl configtest
sudo systemctl restart apache2
sudo systemctl status apache2

Useful links
Рекомендации по теме
visit shbcf.ru