0

如何使用 curl 强制 HAProxy 服务器关联?

使用 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"
4

1 回答 1

0

代替

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

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

请注意 SRV_ID 值周围的额外引号。这必须匹配 'cookie' 和 'check' in 之间的字符串cookie \"172.21.0.2\" check

于 2019-11-17T00:20:39.113 回答