Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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
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 –  Rikih May 24 '11 at 13:52
add comment
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
add comment

Your Answer

 
discard

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.