HAProxy: How to use "Connection: keep-alive"?

Started by syndac, June 13, 2024, 06:38:27 AM

Previous topic - Next topic
I have an app that uses server sent events with the headers, "Connection: keep-alive" and "Keep-Alive: timeout=60". When I test my app locally, I can tell everything works fine and I can see that the connection stays alive and the response headers in Chrome dev tools show both of those headers.

However, when I deploy my app to my server and access via HAProxy, I can see that the connection immediately closes and the response headers are missing.

What settings in HAProxy control this? Nothing really stands out, though I'm not an expert.

Got it. There's a couple things I had to do:

1. Disable HTTP/2 on the frontend Public Service. I'm not sure why. Connection: keep-alive uses HTTP/1.1 and having HTTP/2 available seems to confuse it
2. To the backend, add the following under Options pass-through:

option http-server-close
http-request set-header Connection keep-alive
http-request set-header Keep-Alive timeout=600

Actually, scratch that (above). Options pass-through on the backend doesn't seem to work. Not sure why. On the "Public interface", I had to add this to the options:

http-request set-header Connection keep-alive if acl_<acl fround in config export>
http-request set-header Keep-Alive timeout=600 if acl_<acl fround in config export>