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.

Is it possible to load balance multiple sites which are in the same server using HAproxy ?. We have configured load balancing for one site and now we want to add another website on the same server. Please help me with some examples if its possible.

Thanks,

Santhosh

share|improve this question
    
Never mind. It just works with virtual hosting and HA proxy configuration with out URL filtering. –  santhosh Jan 27 '11 at 8:37
    
Santosh - this is not a forum, answers are for answers, comments are for comments - please read our FAQ when you can. –  Chopper3 Jan 27 '11 at 8:37

1 Answer 1

It's no problem. Remember that HAProxy is simply forwarding CONNECTIONS and doesn't care what the URL is (unless you've setup rules to filter by URL).

It's Apache (or whatever webserver you're using) that has to be configured with the virtual hosts. There should be a different virtual host for every domain you want to use.

A standard HAProxy config will load balance all requests regardless of URL, eg:

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 4096
        daemon

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        redispatch
        contimeout      5000
        clitimeout      50000
        srvtimeout      80000

listen  http_proxy HAPROXY_SERVER_IP:80
        mode http
        balance roundrobin
        option httpclose
        option forwardfor
        cookie SERVERID insert indirect nocache
        server  web01 WEBSERVER1_IP:80 cookie web01 check
        server  web02 WEBSERVER2_IP:80 cookie web02 check

Setting up virtual hosts in Apache is a very common task and you can easily find some information on that with a quick Google search if you're not sure.

share|improve this answer
    
Thanks for the reply Rafiq.. –  santhosh Jan 27 '11 at 5:26
    
Thanks for the reply Rafiq.. Setting up virtualhost in apache isn't my problem. I have only one external ip for my webservers and have configured two websites on it. I have setup URL filter in HAproxy but i'm not sure what to give in the server section server web01 WEBSERVER1_IP:80 cookie web01 check server web02 WEBSERVER2_IP:80 cookie web02 check the Webservers are same for the two websites. –  santhosh Jan 27 '11 at 5:55
    
Why are you using a URL filter? The purpose of using a URL filter in HAProxy is to send different URLs to different servers, which is specifically not what you want to do. If you see my example config above, there is no URL filter present. It simply forwards any HTTP requests, regardless of URL, to the two different webservers. –  Rafiq Maniar Jan 27 '11 at 6:38

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.