强制HAProxy服务器与curl关联吗?

问题描述 投票:0回答:1

如何使HAProxy服务器与curl具有亲和力?

使用curl版本7.58,我已经尝试过:

curl -I \ 
     --proxy-header "Cookie: SRV_ID=172.0.0.2" \
     -x localhost:3001 \
     https://postman-echo.com/headers

我仍在循环中,首次连接负载均衡:

HTTP/1.1 200 Connection established
set-cookie: SRV_ID="172.21.0.3"; path=/

HTTP/1.1 200 OK
Content-Length: 134
Content-Type: application/json; charset=utf-8
Date: Sat, 16 Nov 2019 22:05:22 GMT
ETag: W/"86-77S8g6gXGJd5i+Emjsb0b9sIcac"
Server: nginx
set-cookie: sails.sid=s%3AC1VtUY_GI...HsNx7LDg; Path=/; HttpOnly
Vary: Accept-Encoding
Connection: keep-alive

HAProxy 2.0.8相关后端配置:

  backend http-backend
    mode http
    balance roundrobin
    default-server inter 2s fastinter 2s downinter 2s fall 3 rise 2
    cookie SRV_ID insert

    server container-172-21-0-2 172.21.0.2:3000 cookie \"172.21.0.2\" check

    server container-172-21-0-3 172.21.0.3:3000 cookie \"172.21.0.3\" check

我能够保存并发送已保存的cookie,并且我可以编辑cookie-jar文件以达到所需的效果,但是如何在一行中编写curl命令?

curl -b cookies.txt -c cookies.txt -x localhost:3001 http://scooterlabs.com/echo

Cookites.txt内容:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

scooterlabs.com FALSE   /       FALSE   0       SRV_ID  "172.21.0.2"
curl haproxy session-affinity
1个回答
0
投票
替换

curl -I \ --proxy-header "Cookie: SRV_ID=172.0.0.2" \ -x localhost:3001 \ https://postman-echo.com/headers

with

curl -I \ --proxy-header "Cookie: SRV_ID=\"172.0.0.2\"" \ -x localhost:3001 \ https://postman-echo.com/headers

[请注意,SRV_ID的值附近要用引号引起来。这必须与cookie \"172.21.0.2\" check中'cookie'和'check'之间的字符串匹配。
© www.soinside.com 2019 - 2024. All rights reserved.