Nginx: Setting Up HTTP authentication 
Prompting users for a password before accessing a page.

Place the following two entries in nginx configuration file:

auth_basic "Restricted";                                
auth_basic_user_file /var/www/mywebsite.com/.htpasswd;

Eg:
  location / {
root /var/www/mywebsite.com;
index index.html index.htm;
auth_basic "Restricted"; #For Basic Auth
auth_basic_user_file /var/www/mywebsite.com/.htpasswd; #For Basic Auth
}


The .htpasswd must contain:
username:password

Generate the password with this command:
[root@IBM ~]#printf "USERNAME:$(openssl passwd -crypt PASSWORD)\n" >> htpasswd


[ view entry ] ( 1382 views )   |  print article

<<First <Back | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Next> Last>>



2024 By Angel Cool