Nginx : Basic Authentication
[1] .Add setting on a site config you'd like to set.
For example, set Basic Auth under the [/auth-basic] directory.
[root@www ~]# dnf -y install httpd-tools
[root@www ~]# vi /etc/nginx/conf.d/ssl.conf
# add into the [server] section
server {
.....
.....
location /auth-basic/ {
auth_basic "Basic Auth";
auth_basic_user_file "/etc/nginx/.htpasswd";
}
[root@www ~]# mkdir /usr/share/nginx/html/auth-basic
[root@www ~]# systemctl restart nginx
# add user for Basic authentication
[root@www ~]# htpasswd -c /etc/nginx/.htpasswd cent
New password: # set any password
Re-type new password:
Adding password for user cent
# create a test page
[root@www ~]# vi /usr/share/nginx/html/auth-basic/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Authentication
</div>
</body>
</html>
[2] . Access to the test page from any client computer with web browser. Then authentication is required as settings, answer with a user added in [1].
[3]. It's OK if authentication is successfully passed and test page is displayed normally.
Comments
Post a Comment