Ubuntu 18.04
Sponsored Link

Nginx : Configure Basic Auth
2018/07/02
 
Enable Basic Authentication to restrict access on specific web pages.
[1] For example, set Basic Auth under the [/auth-basic] directory.
root@www:~#
apt -y install apache2-utils
root@www:~#
vi /etc/nginx/sites-available/default
# add into the [server] section

        location /auth-basic {
            auth_basic            "Basic Auth";
            auth_basic_user_file  "/etc/nginx/.htpasswd";
        }

root@www:~#
htpasswd -c /etc/nginx/.htpasswd ubuntu

New password:    
# set password

Re-type new password:
Adding password for user ubuntu
root@www:~#
mkdir /var/www/html/auth-basic

root@www:~#
systemctl restart nginx
[2] Access to the test page with Web browser from any Client and authenticate with a user which is added with htpasswd.
[3] Just accessed.
Matched Content
 
Tweet