I need to protect /servis directory with a password authentication. So, I created a password file like this:
sudo nano /etc/nginx/conf.d/.htpasswd
and I save a user credentials
myuser:$apr1$Xw/j.............
I changed my virtual server definition file
sudo nano /etc/nginx/sites-enabled/inscubator.cz
in this way:
server {
listen 80;
server_name inscubator.cz www.inscubator.cz;
root /var/www/inscubator.cz;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location ~ /\.cfg {
deny all;
}
location /admin {
auth_basic "Restricted Access!";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
}
location /servis {
auth_basic "Restricted Access!";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
}
}
I restarted NGINX and I restarted the server as well. Unfortunately, PHP scripts in both directories ( admin and servis ) are freely accessible. What could be wrong?