我已经使用NGINX在一个子域上启用了密码保护,并且写了一个小脚本,可以轻松添加用户。 当我input密码时,对话框消失,立即popup。
这是我的密码生成器脚本:
#!/bin/bash if [ -z "$1" ] then echo "Username Expected as first param" elif [ -z "$2" ] then echo "Password Expected as second param" else htpasswd -b /home/me/.passwords $1 $2 /etc/init.d/nginx reload fi
运行:
./create-password test password
我可以看到以下输出:
为用户testing添encryption码
[ok]重新加载nginxconfiguration(通过systemctl):nginx.service。
里面/home/me/.passwords我可以看到以下条目:
test:$apr1$t.LpBHkW$bEBEMK1HRBqAvvkB9cQ.I.
在我的nginxconfiguration( /etc/nginx/sites-enabled/blah )中,我有以下几点:
server { listen 80; server_name blah.example.com; auth_basic "Restricted Content"; auth_basic_user_file /home/me/.passwords; location / { proxy_pass http://127.0.0.1:6999; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
如果我inputtest和testing ,
该对话框将消失并再次popup。
我没有看到在NGINX error.log中的任何错误, access.log只显示基本上是一个错误401,未经授权:
___.___.___.___ - test [16/Apr/2016:09:36:38 +0000] "GET / HTTP/1.1" 401 1421 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623 .110 Safari/537.36"
取消密码popup,我看到以下内容:
我在该子域上运行jenkins,当我改变我的http用户名和密码,以匹配jenkins用户名和密码,它的工作。
jenkins也可能使用httpvalidation标题。