我使用以下配置从本地127.0.0.1:2000代理访问互联网。:
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen appname 0.0.0.0:2000
mode http
stats enable
acl white_list src 127.0.0.1
tcp-request content accept if white_list
tcp-request content reject
stats uri /haproxy?stats
stats realm Strictly\ Private
stats auth special_admin:special_username
balance roundrobin
option httpclose
option forwardfor
server lamp1 23.123.1.110:3128 check
不幸的是,我需要通过http基本身份验证" special_admin:special_username"对我的外部代理23.123.1.110进行身份验证。 我的问题是,有没有办法使用基本身份验证,如:
server lamp1 http://special_admin:special_username@23.123.1.110:3128 check
由于
答案 0 :(得分:6)
在您的示例中,您只需要使用授权方法添加必要的Authorization
标头,并将username:password
编码为base64,如下所示:
reqadd Authorization:\ Basic\ c3BlY2lhbF9hZG1pbjpzcGVjaWFsX3VzZXJuYW1l
我创建了base64编码的字符串,如下所示:
echo -n "special_admin:special_username" | base64
有关HTTP基本授权的详细信息,请参阅https://en.wikipedia.org/wiki/Basic_access_authentication#Client_side
答案 1 :(得分:1)
下面列出的步骤对我有用。
# haproxy conf
global
log 127.0.0.1 local1
maxconn 4096
defaults
mode http
maxconn 2048
userlist AuthUsers
user admin password $6$SydPP/et7BGN$C5VIhcn6OxuIaLPhCDCmzJyqDYQF8skik3J6sApkXPa6YPSVGutcgQPpdX/VEycGNi3sw7NxLSflEb53gzJtA1
frontend nginx-frontend
bind *:5000
mode http
timeout connect 5s
timeout client 5s
timeout server 5s
default_backend nginx-backend
acl authusers_acl http_auth(AuthUsers)
http-request auth realm nginx-backend if !authusers_acl
backend nginx-backend
server nginx nginx:80 check inter 5s rise 2 fall 3
sudo apt-get install whois
mkpasswd -m sha-512 admin @ 456
$ 6 $ gnGNapo / XeXYg39A $ T / 7TDfMrZXUDPbv5UPYemrdxdh5xEwqBrzSbpJYs9rfxLbQtgQzxyzkSGWIVOEGze8KrsA0urh3 / dG.1xOx3M0
#部署容器以测试配置
sudo docker run -d --name nginx nginx
sudo docker run -d -p 5000:5000 --name haproxy --link nginx:nginx -v /home/users/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg haproxy