Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize login authentication by configuring Basic Auth in Nginx

Shulou Source: shulou.com Published: 2022-06-01 20:38:09 10月03日 Update

This article shows you how to configure Basic Auth to achieve login authentication in Nginx, the content is concise and easy to understand, absolutely can make you shine, through the detailed introduction of this article I hope you can gain something.

1. Make sure you have httpd-tools installed

yum install httpd-tools -y

2. Create authorized users and passwords

htpasswd -c -d /usr/local/openresty/nginx/conf/pass_file magina

This configuration file storage path can be arbitrarily specified, here I specify is the nginx configuration file directory, where magina refers to the user name allowed to log in, this can be customized

3. configure Nginx

The general configuration is as follows:

server { listen 80; server_name res.yinnote.com; auth_basic "login authentication"; auth_basic_user_file /usr/local/openresty/nginx/conf/pass_file; autoindex on; autoindex_exact_size on; autoindex_localtime on; root /mnt/html/resource; index index.html index.php;}

auth_basic and auth_basic_user_file are authentication configurations, note that the path to the password file must be generated above

4. use

#In the browser, enter the address directly in the browser, and the user password input box will pop up. Enter it to access #Use wgetwget --http-user=magina --http-passwd=123456 http://res.yinnote.com/xxx.zip# Use curlcurl -u magina:123456 -O http://res.yinnote.com/xxx.zip The above content is how to configure Basic Auth in Nginx to achieve login authentication. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Tags: Configuration login authentication password file user input Zhongtong content skills browser knowledge path browsing concise concise address that is articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Shulou Technology Linux vpn