tengo un servidor con nginx+apache y quiero proteger un directorio de un virtualhost que tengo con auth_basic, como comento el servidor tiene diferentes vhosts tanto de apache como de nginx.
El dominio que quiero proteger es este http://ejemplo1.com/api/documentation
Para ello he hecho estos pasos
1- Crear fichero htpassword
location /api/documentation {
auth_basic "Restricted";
auth_basic_user_file /home/user1/nginx/ejemplo1.com/.htpasswd;
}
Aquí tengo la duda de esta "location" ya que esta ruta puede existir en los distintos vhost de nginx.
2 - Generar htpasswd
htpasswd -c /home/user1/nginx/ejemplo1.com/.htpasswd
3 - Reinicio nginx /etc/init.d/nginx reload
Pruebo a entrar al dominio y no me pide user y pwd. Adjunto también la configuración del vhost.
server {
listen 80;
server_name test.ejemplo1.com;
root /var/www/html/ejemplo1/test/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
Gracias