缺月挂梧桐 漏断人初静

导航

利用nginx添加账号密码验证

 1 server {
 2     listen              80;
 3     server_name         xxx.com;
 4 
 5     location / {
 6         proxy_pass  http://10.10.10.10:5601;
 7         proxy_redirect     off;
 8         proxy_set_header   Host             $host;
 9         proxy_set_header   X-Real-IP        $remote_addr;
10         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
11         #allow  124.90.53.17; 
12         auth_basic "The Kibana Monitor Center";
13         auth_basic_user_file  /usr/local/.passwd;
14         proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
15         proxy_max_temp_file_size   0;
16         proxy_connect_timeout      60;
17         proxy_send_timeout         900;
18         proxy_read_timeout         900;
19         proxy_buffer_size          34k;
20         proxy_buffers              4 32k;
21         proxy_busy_buffers_size    64k;
22         proxy_temp_file_write_size 64k;
23     }
24 }

 

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

 

posted on 2018-11-26 15:15  勤劳の洗碗机  阅读(2395)  评论(0编辑  收藏  举报