Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have HAProxy acting as a proxy in front of:

  • An NGinx instance
  • An in-house load balancer in front of multiple dynamic services exposed with (websockets)

My problem is that from time to time my connections are proxied correctly to my cluster, and then randomly it fallsback to routing to NGinx which obviously is annoying and meaningless since NGinx isn't mean't to handle the request.

This happens when requesting for URLs of the format :*

There's an ACL in the HAProxy config to match the '/backends/*' path.

Here's a simplified version of my HAProxy config (removed extra unrelated entries and changed names):

    maxconn 4096
    user haproxy
    group haproxy
    nbproc 4 

    mode http
    timeout server 86400000
    timeout connect 5000
    log global

#this frontend interface receives the incoming http requests
frontend http-in
    mode http

    #process all requests made on port 80
    bind *:80

    #set a large timeout for websockets
    timeout client 86400000

    # Default Backend
    default_backend www_backend

    # Loadfire (socket cluster)
    acl is_loadfire_backends path_beg /backends
    use_backend loadfire_backend if is_loadfire_backends

# NGinx backend
backend www_backend
    server www_nginx localhost:12346 maxconn 1024

# Loadfire backend
backend loadfire_backend
    option forwardfor # This sets X-Forwarded-For
    option httpclose
    server loadfire localhost:7101 maxconn 2048

It's really quite confusing for me why the behaviour appears to be "random", since being hard to reproduce it's hard to debug.

I appreciate any insight on this.

share|improve this question
up vote 0 down vote accepted

The problem was caused by the fact that when multiple HTTP requests are carried over the same TCP connection, the first request goes through the acl matching process and context switching to get a backend, but that does not hold for the following connections.

So to fix the problem, one should either one of the following in their frontend section :

option httpclose


option http-server-close

The above worked for me (I choosed the latter, http-server-close).

I found this documentation entry to be very useful: HAProxy documentation on Google Docs for http-close-server (the other entries are useful too).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.