nginx 添加basic auth

生成密码文件

htpasswd -c -d conf/htpasswd kibana
printf "kibana:$(openssl passwd -crypt 4Bo*3Jdhk)\n" >>htpasswd

添加配置文件

server {} 中添加,还可以在http,location等配置段中添加
auth_basic "nginx basic auth";
auth_basic_user_file htpasswd;

nginx的启动和停止

/usr/sbin/nginx --启动
pkill nginx --停止
nginx -s reload --重新加载配置文件

限制:启用了upstream的不能添加

nginx_tcp_proxy_module

tcp {
upstream ha {
server 192.168.164.245:2255;
}

server {
listen 2255;
proxy_pass ha;

auth_basic "login test";
auth_basic_user_file conf/htpasswd;

}
}

猜你喜欢

转载自blog.51cto.com/395469372/2317862