server { listen ; server_name xxx.com; location / { proxy_pass http://10.10.10.10:5601; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #allow 124.90.53.17; auth_basic "The Kibana Monitor Center"; auth_basic_user_file /usr/local/.passwd; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size ; proxy_connect_timeout ; proxy_send_timeout ; proxy_read_timeout ; proxy_buffer_size 34k; proxy_buffers 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }
1、在location /下添加
auth_basic "The Kibana Monitor Center";
auth_basic_user_file /usr/local/.passwd;
2、yum install httpd-tools -y
3、 htpasswd -bc /usr/local/.passwd wuyun qwe123\!\@\# #特殊符号要用 \ 转义
此时重启nginx,再登录访问域名时就需要输入账号密码了。不输入密码会报401 Authorization Required错误
也可以用页面设置密码
登陆http://tool.oschina.net/htpasswd 输入用户名和密码,在线生成加密密码
将生成的密码写入/usr/local/.passwd文件中
echo "wuyun:$apr1$TrU5vUSC$RBuz3xG67Mr2pnAV596N5" >/usr/local/.passwd