Protecting Nginx directories with Password
2022-12-24
Protecting Nginx directories with Password
- Add
auth_basic
to nginx configuration file.
location /subdirectory {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/example.com/.htpasswd;
}
- Create the .htpasswd file with specified username.
htpasswd -c /etc/nginx/htpasswd/example.com/.htpasswd USERNAME
- Restart Nginx.
systemctl restart nginx
-EOF-