1

I want to create a simple load balancer for the two servers.

The problem is with CNAME records, I think.

Let's say I have two the same applications on AppFog.com.

app1.aws.af.cm and app2.aws.af.cm

Here is my haproxy.cfg file:

global
    maxconn 2000
    daemon

defaults
    mode http
    clitimeout 60000
    srvtimeout 30000
    contimeout 4000
    option httpclose

listen http_proxy 
    bind [myip]:80
    mode http
    stats enable
    stats auth user:passwd
    stats uri /stats
    balance source
    option httpchk
    option forwardfor
    server host01 app1.aws.af.cm:80 maxconn 300 check
    server host02 app2.aws.af.cm:80 maxconn 300 check

But this only resolving IP for domain app1.aws.af.cm and app2.aws.af.cm, which obviously doesn't work if I open this IP in web browser.

The problem is that AppFog doesn't have public IP for application (same as OpenShift).

How to do that Haproxy to perform a proper connection between Load Balancer and this two servers?

Example:

This is real app - http://freechat.eu01.aws.af.cm

Haproxy only resolves IP for this domain which is 46.51.204.8:80

Of course this IP will not show my application, only an error page.

Sorry for my poor English.

2 Answers 2

1

Having a little trouble following your issue. However, one thing to keep in mind is that HTTP requests have the requested domain name as the Host field in the HTTP header.

Therefore load balancers and web servers will generally direct the request or respond to the request if the name binding matches the host header.

Perhaps this clears things up a little, or maybe you can try to rephrase your question?

7
  • "HTTP requests have the requested domain name as the Host field in the HTTP header" This is what I want. How to add Host field in the HTTP header in haproxy.cfg?
    – user123354
    Jun 3, 2012 at 15:14
  • For that you would use reqadd to add, or reqrep to replace - code.google.com/p/haproxy-docs/wiki/HTTPHeaderManipulation Jun 3, 2012 at 15:17
  • I tried this, but this doesn't work. "Load balancers and web servers will generally direct the request or respond to the request if the name binding matches the host header" - what "name" exactly?
    – user123354
    Jun 3, 2012 at 16:10
  • The host field in the http header. What generates the error? If the provider doesn't give you a dedicated ip, then you probably can't access your sites via ip because they are already directing based on the name. In other words, maybe they return the error before it even gets to your haproxy instance Jun 3, 2012 at 16:59
  • You talk about my Haproxy instance? It works fine, with normal IP of my other servers. Only AppFog's/OpenShift servers doesn't work, cos they must have thier Host header... so maybe I do something wrong. How to exactly add this Host field in haproxy.cfg? I can't find good example.
    – user123354
    Jun 3, 2012 at 17:26
0

I am not sure I fully understand this either. When I had sites that bind to a host header rather than IP address, all I had to do was make sure the health check uses the header also:

option httpchk HEAD /mystatus HTTP/1.1\r\nHost:\ example.com

This then allows it to pass the health check. When a client connects they will be inputting the proper domain such as www.example.com. To my knowledge the host header informaion is not lost so connections will work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .