2
votes

Is it possible to load balance across a set of nodejs servers using apache? I would also need to configure apache with a cert to provide ssl and only serve out https requests.

Simple setup would be 2 apache servers that would be my load balancers. All requests would come into one of those 2 load balancers over https.

From there the load balancers would need to determine which server to route the request to. This would be one of 6 servers that are all running the same node process.

I know there is mod_cluster, but I have only used that with JBoss setup and not really sure if this would work with nodejs servers.

I also realize this might not be the best setup as node is single threaded and I could try something like node cluster. However node cluster seems to scale vertically instead of horizontally.

I also know there is nginx and haproxy, although I have never used either of them and have a lot more experience with apache. Also not sure if haproxy and nginx support allowing only ssl connections with a certificate.

Is this type of load balancing possible w/ apache and if so how?

2

2 Answers

5
votes

The use of apache is independt of the server used behind if you use the mod_proxy module. So you can also look at all the apache->tomcat examples using mod_proxy.

After questions how to do it I added the following example:

<VirtualHost *:80>
        ProxyRequests off

        ServerName domain.com

        <Proxy balancer://mycluster>
                # WebHead1
                BalancerMember http://10.176.42.144:80
                # WebHead2
                BalancerMember http://10.176.42.148:80

                # Security "technically we aren't blocking
                # anyone but this the place to make those
                # chages
                Order Deny,Allow
                Deny from none
                Allow from all

                # Load Balancer Settings
                # We will be configuring a simple Round
                # Robin style load balancer.  This means
                # that all webheads take an equal share of
                # of the load.
                ProxySet lbmethod=byrequests

        </Proxy>

        # balancer-manager
        # This tool is built into the mod_proxy_balancer
        # module and will allow you to do some simple
        # modifications to the balanced group via a gui
        # web interface.
        <Location /balancer-manager>
                SetHandler balancer-manager

                # I recommend locking this one down to your
                # your office
                Order deny,allow
                Allow from all
        </Location>

        # Point of Balance
        # This setting will allow to explicitly name the
        # the location in the site that we want to be
        # balanced, in this example we will balance "/"
        # or everything in the site.
        ProxyPass /balancer-manager !
        ProxyPass / balancer://mycluster/

</VirtualHost>
3
votes

Yes it is possible, if you are asking how to setup Apache Load Balancers, Check this out.

Have you seen node-http-proxy? Great little walkthrough here not too intimidating if you want to keep it all Node.