Sometimes we build a file server through nginx, which is generally open, but we hope that the server will not let others see it. Someone may set up a login system, but it is too troublesome, or maybe it is not necessary. The simple way is to configure Basic Auth login authentication.
1. Make sure you have httpd-tools installed
1 |
yum install httpd-tools -y |
2. Create an authorized user and password
1 |
htpasswd -c -d /usr/local/nginx/conf/pass_file nginxer |
This configuration file storage path can be customized, here I point to the nginx configuration file directory, the “nginxer” is the username that is allowed to log in, the username can be customized too.
3. Configure Nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
server { listen 80; server_name files.nginxer.com; auth_basic "Login authentication"; auth_basic_user_file /usr/local/nginx/conf/pass_file; autoindex on; autoindex_exact_size on; autoindex_localtime on; root /mnt/html/resource; index index.html index.php; } |
the auth_basic and auth_basic_user_file are certified configurations, please note that the path to the password file must be generated above (step 2).
4.Use Basic Auth login authentication
#Use in the browser
Enter the url in the browser, the user password input box will be popup.
1 2 3 4 5 |
# Use wget wget --http-user=nginxer --http-passwd=123456 http://files.nginxer.com/somefiles.tar.gz # Use curl curl -u nginxer:123456 -O http://files.nginxer.com/somefiles.tar.gz |
This article was first published by V on 2018-10-04 and can be reprinted with permission, but please be sure to indicate the original link address of the article :http://www.nginxer.com/records/nginx-basic-auth-login-authentication-configures/