To restrict access to certain pages of the site, you need to set up a link between the htaccess configuration file and the htpasswd password file. There can be several directories, as well as users. Make sure the apache2-utils package is present, as a rule it is already installed, if not, use the yum install command for centos or apt install for debian/ubuntu.
Let's create a file with passwords:
htpasswd -c /etc/apache2/.htpasswd username
Where username is the username, after you will be prompted to come up with a password.
Set up the virtual host file:
vi /etc/apache2/sites-enabled/default.conf
vi /etc/apache2/sites-enabled/default-ssl.conf
Depending on the type of your configuration, add the following lines:
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
To apply the settings, restart the service:
systemctl restart apache2
Done, following the path specified in the settings, the browser will require you to enter your login and password.
No Comments Yet