Nginx setup login verification

Nginx setup login verification

The project deployed by Nginx is on the public network. Sometimes we don't want anyone to be able to access it. Therefore, we need to set login authentication information to prevent unrelated people from seeing sensitive information.

htpasswdCommand to generate a password file

If there is no htpasswdcommand, you need to installhttpd

yum install httpd

htpasswdGenerate password file after installation command

htpasswd -cm /usr/local/nginx/htpasswd george

Where georgeis the username.
Need to enter a password and verify the password again.
After the success can be seen in the /usr/local/nginx/swells became the htpasswdfiles.

Configure Nginx

In nginx.confthe server/locationconfiguration as follows:

location / {
    
    
    proxy_pass http://127.0.0.1:5601;
    # 如下两行
    auth_basic "登录验证";
    auth_basic_user_file /usr/local/nginx/htpasswd;
}

Update Nginx configuration or restart Nginx

nginx -s reload
nginx -s stop
nginx

When you visit again, you can see that you need to enter a user name and password to access.
Insert picture description here
Enter the user name and password to be able to access after successful verification.

Guess you like

Origin blog.csdn.net/qq_27198345/article/details/113799246