Protecting Nginx directories with Password

2022-12-24

Protecting Nginx directories with Password

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

-EOF-

Home
Hits