Nginx : Basic Authentication2024/11/08 |
Set Basic Authentication to limit access on specific web pages. |
|
[1] |
Username and password are sent with plain text on Basic Authentication, |
[2] | 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";
}
# add user for Basic authentication [root@www ~]# htpasswd -5 -c /etc/nginx/.htpasswd fedora
New password: # set any password
Re-type new password:
Adding password for user fedora
<html> <body> <h1 style="width: 100%; font-size: 40px; text-align: center;"> Test Page for Basic Authentication </h1> </body> </html> |
[3] | Access to the test page from any client computer with web browser. Then authentication is required as settings, answer with a user added in [2]. |
[4] | That's OK if authentication is successfully passed and test page is displayed normally. |
Sponsored Link |