Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

This configuration is intended to send people to Node unless it's a .gif, .jpg etc., but it doesn't seem to work (it always sends them to Nginx):

frontend all
  timeout client 86400000

  # ... unless they're on websockets, which Nginx can't handle
  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket hdr_beg(Host) -i ws
  # static assets
  acl url_static path_end .jpg .jpeg .gif .png .ico .pdf .js .css .flv .swf
  acl is_domain hdr_end(host) -i
  # ... or are using, which is served by node
  acl is_websocket path_beg /

  # conditional for hitting node
  use_backend node_backend  if !url_static is_domain
  use_backend nginx_backend if url_static

  # always send people to nginx
  default_backend nginx_backend

This is haproxy 1.4.

Edit: I should point out I'm serving static assets off the same domain as the Node.js stuff, but via Nginx. So the hostname is the same in both cases, I just want to forward requests for static assets to Nginx instead.

share|improve this question

how if

from you may try using Header Upgrade and Connection

 # if header Upgrade = WebSocket and Connection=Upgrader
 acl is_websocket hdr(Upgrade) -i WebSocket AND hdr(Connection) -i Upgrade
 use_backend node_backend  if is_websocket

 # else
 default_backend nginx_backend
share|improve this answer
Doesn't work - the first hit is on Node for everything, then it hits Nginx for everything, which 404s. – Brad Wright May 24 '11 at 6:46
i revised the answer, may be detect using Upgrade and Connection header would help – chocripple May 24 '11 at 13:52
up vote 0 down vote accepted

I fixed this by adding option httpclose inside the backends. Seems the implicitly held connection was ending up in Nginx. I found a clue to the answer here.

backend node_backend
  # node.js
  option forwardfor # This sets X-Forwarded-For
  option httpclose
  # .. etc ..

backend nginx_backend
  # nginx
  option forwardfor
  option httpclose
  # .. etc ..
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.