0

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 0.0.0.0:80
  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 SUB.DOMAIN.com
  # ... or are using Socket.io, which is served by node
  acl is_websocket path_beg /socket.io

  # 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.

Brad Wright
  • 261
  • 2
  • 7

2 Answers2

1

how if

from http://anismiles.wordpress.com/2011/01/25/websocket-and-node-js-why-shud%E2%80%99ya-care/ 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
chocripple
  • 2,109
  • 14
  • 9
0

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 ..
Brad Wright
  • 261
  • 2
  • 7