Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

Haproxy cookie prefix in backend configuration doesn't append server name

The Haproxy is configured as a load balancer and there are a couple of backend servers. A call to a REST endpoint on the backend server creates a cookie and adds it to the HttpServletResponse. The cookie is visible on the client side. No issues so far. The expectation is that from here on subsequent calls to the backend should be catered by the same server that set the cookie.

Haproxy Configuration:

[xxx]# haproxy -v : HA-Proxy version 1.5.18 2016/05/10

backend bk_appln
    mode http
    balance leastconn
    option httplog
    option forwardfor
    option abortonclose
    timeout tunnel 60m
    stick-table type string size 5m expire 10h
    stick on req.cook(cookie_by_server)
    hash-type consistent
    cookie cookie_by_server prefix nocache
    http-request set-header X-Forwarded-Port %[dst_port]
    http-request add-header X-Forwarded-Proto https
    redirect scheme https if !{ ssl_fc }
    server server1 ip1:443 ssl verify none check-ssl cookie S1 check
    server server1 ip2:443 ssl verify none check-ssl cookie S2 check

I am not sure if cookie cookie_by_server prefix nocache & stick on req.cook(cookie_by_server) both are required for stickiness as it is not clear in Haproxy documentation, so I tried removing stick-table and stick on & cookie separately to see how Haproxy behaves. Atleast when stick-table and stick on are removed from backend configuration with just cookie cookie_by_server prefix nocache I expected the server name to have been prefixed by Haproxy to the cookie value set by backend. But it didn't happen & subsequent calls are dispersed to backend servers based on leastconn algorithm.

Is my understanding on the cookie prefix wrong, or is the backend configuration itself is wrong or is Haproxy not behaving as expected?

I couldn't find any resources that discussed this issue in detail. So any help is much appreciated.

question from:https://stackoverflow.com/questions/65925104/haproxy-cookie-prefix-in-backend-configuration-doesnt-append-server-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...