Nginx : Basic Authentication2022/05/10 |
Set Basic Authentication to limit access on specific web pages.
|
|
[1] |
Username and password are sent with plain text on Basic Authentication,
so Use secure connection with SSL/TLS setting, refer to here. |
[2] | Add setting on a site config you'd like to set. For example, set Basic Authentication 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
server {
.....
.....
location /auth-basic {
auth_basic "Basic Auth";
auth_basic_user_file "/etc/nginx/.htpasswd";
}
# add users for basic authentication root@www:~# htpasswd -c /etc/nginx/.htpasswd ubuntu New password: # set any password Re-type new password: Adding password for user ubuntu <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Test Page for Basic Authentication </div> </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 |
|