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;

}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章