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.
htpasswd
Command to generate a password file
If there is no htpasswd
command, you need to installhttpd
yum install httpd
htpasswd
Generate password file after installation command
htpasswd -cm /usr/local/nginx/htpasswd george
Where george
is 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 htpasswd
files.
Configure Nginx
In nginx.conf
the server/location
configuration 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.
Enter the user name and password to be able to access after successful verification.