Vai al contenuto

Apache Auth

Installazione

Bash
sudo apt update
Bash
sudo apt install apache2-utils

Creazione degli utenti

Per creare il file:

Bash
sudo htpasswd -c /etc/apache2/.htpasswd username
per l'inserimento dei successivi utenti:
Bash
sudo htpasswd /etc/apache2/.htpasswd username2

Configurazione file apache

Bash
sudo nano /etc/apache2/sites-available/your_domain.conf

Da:

Bash
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your_domain
    ServerAlias www.your_domain
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory "/var/www/your_domain">
    </Directory>
</VirtualHost>

A:

Bash
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName your_domain
    ServerAlias www.your_domain
    DocumentRoot /var/www/your_domain
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

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

Verifica configurazione:

Bash
sudo apache2ctl configtest

Riavvio apache

Bash
sudo systemctl restart apache2


Fonte: https://www.digitalocean.com/