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.

I am trying to set up haproxy to route to backends depending on the the subdomain that was used in the http request. Eg I have a regular web server running on port 8000 and an application server waiting for websocket connections running on port 8001 on the same IP adress. I now want that if the user hits app.mydomain.com:80 that he is redirected to port 8001 and if he hits www.mydomain.com (or any other subdomain) that he is redirected to the webserver on port 8000.

I came up with a plain configuration that I think should accomplish that (it is based loosly on this question):

frontend all 0.0.0.0:80
  timeout client    86400000
  acl aclMS1 hdr_dom(host) -i app
  use_backend   beMS1   if aclMS1
  default_backend   beWEB

backend beMS1
  timeout server 86400000
  server srvMS1 localhost:8001 maxconn 200 check

backend beWEB
  server webserver localhost:8000 maxconn 200 check

However, it seems like this does not work. I always end up at my webserver on port 8000. What am I doing wrong?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I figured out how to get it working. I was missing the mode http option. My config now looks like this and works like a charm:

defaults
  mode http
  timeout server 50000ms
  timeout server 50000ms
  timeout server 50000ms

frontend all 0.0.0.0:80
  timeout client    86400000
  acl aclMS1 hdr_dom(host) -i app
  use_backend   beMS1   if aclMS1
  default_backend   beWEB

backend beMS1
  timeout server 86400000
  server srvMS1 localhost:8001 maxconn 200 check

backend beWEB
  server webserver localhost:8000 maxconn 200 check
share|improve this answer

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.