Skip to main content

Password_Protected_Website_Nginx

Passowrd Protection in Website running on Nginx Hosted on Linux Remote Server or VPS​

  • Install Util
sudo apt install apache2-utils
  • Create Login Credentials
sudo htpasswd -c /etc/nginx/.htpasswd user_name
  • Verify that Credential has been Created
cat /etc/nginx/.htpasswd
  • Go to /etc/nginx/sites-available
cd /etc/nginx/sites-available
  • Open the Required Virtual Host File
sudo nano default
  • Add below Content
location /admin {
try_files $uri $uri/ =404;
auth_basic "admin area";
auth_basic_user_file /etc/nginx/.htpasswd;
}
  • Restart Nginx
sudo service nginx restart