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 have a video conversion php script and I want to get it load-balanced the simplest way by having the traffic diverted to various sub-domains which will be hosted on different dedicated boxes.

so basically what needs to be done is to have users redirected to server1.mydomian.com, server2.mydomian.com, server3.mydomian.com.... and so on whenever the user lands on www.mydomain.com sequentially.

Pls. suggest how this can be achieved via apache or nginx and what would be a better choice to do so ?

share|improve this question
    
do you want the users to hit the machines directly, or one box that loadbalances all? –  Joris Mar 5 '11 at 19:42
    
Directly hit the machines. –  iTech Mar 9 '11 at 1:26

2 Answers 2

up vote 0 down vote accepted

You can achieve this with Apache using mod_proxy and mod_balancer_proxy.

If you rely on PHP sessions, read this article: http://www.markround.com/archives/33-Apache-mod_proxy-balancing-with-PHP-sticky-sessions.html

The apache config is pretty easy:

Given that you run debian:

apt-get install apache2
a2enmod proxy
a2enmod proxy_balancer

go to /etc/apache2/conf.d and create a file.. let's call it load-balancer. Put this in it:

ProxyPass / balancer://lbcluster/
ProxyPassReverse / balancer://lbcluster/ # The trailing slash is important!
ProxyPreserveHost On # This will preserce the host header for the backend servers

<Proxy balancer://lbcluster>
  BalancerMember http://10.242.56.23
  BalancerMember http://10.242.56.24
</Proxy>

And you should be good to go :)

Fire up your browser and read some of the Apache docs for knowledge on fine tuning to your needs.

share|improve this answer

Using nginx you can try this:

http {
  upstream mydomain {
    server server1.mydomain.com;    
    server server2.mydomain.com;    
    server server3.mydomain.com;    
  }

  server {
    listen 80;
    server_name www.mydomain.com;
    location / {
      rewrite ^(.*)$ http://mydomain/$1 break;
    }
  }

Never tested it so YMMV.

share|improve this answer
    
And what would be the apache directives to achieve this ? –  iTech Mar 6 '11 at 2:26
    
There's mod_proxy_balancer but I am not sure if it will do what you want. –  coredump Mar 6 '11 at 2:32

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.