Setting up a load balancer using Apache 2.4
Here's a complete balancer config that should work:
<Proxy balancer://pop>
BalancerMember http://pop1.local/ loadfactor=1
BalancerMember http://pop2.local/ loadfactor=1
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://pop/
As stated in documentation, if the first part of ProxyPass
ends with a /
the second part also needs to end with the /
:
If the first argument ends with a trailing /, the second argument should also end with a trailing / and vice versa. Otherwise the resulting requests to the backend may miss some needed slashes and do not deliver the expected results.
You also need to make sure that ProxyRequests
is set to off
.
Related videos on Youtube
Mehran
Updated on September 18, 2022Comments
-
Mehran over 1 year
I'm trying to setup a load balancer with Apache 2.4 but I can't make it work.
Here's what I wrote in my http.conf file:
<Proxy balancer://pop> BalancerMember http://pop1.local/ loadfactor=1 BalancerMember http://pop2.local/ loadfactor=1 ProxySet lbmethod=byrequests </Proxy>
And this is the list of loaded Apache modules:
core mod_so http_core event mod_authn_file mod_authn_core mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_core mod_access_compat mod_auth_basic mod_watchdog mod_reqtimeout mod_filter mod_mime mod_log_config mod_env mod_headers mod_setenvif mod_version mod_proxy mod_proxy_connect mod_proxy_ftp mod_proxy_http mod_proxy_fcgi mod_proxy_scgi mod_proxy_wstunnel mod_proxy_ajp mod_proxy_balancer mod_proxy_express mod_slotmem_shm mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_bybusyness mod_lbmethod_heartbeat mod_unixd mod_heartmonitor mod_status mod_autoindex mod_dir mod_alias mod_rewrite mod_php5
To test, I've setup three VMs, one for load balancer and two for back-end webservers. Using hosts file I introduced three domains in all of the machines:
192.168.0.100 pop.local 192.168.0.101 pop1.local 192.168.0.102 pop2.local
pop.local
is my load balancer and other two are the back-ends. Having ainfo.php
file created on each of the back-ends, I can load them enteringhttp://pop1.local/info.php
andhttp://pop2.local
. But when I typehttp://pop.local
, a404 File not found
error returns.The Apache on
pop.local
loads normally as if there's noProxy balancer
is set. It can even serve its own local files without a problem.What's the problem? Am I missing something?
[UPDATE]
Here's the contents of my log file:
error_log:
[Wed Oct 02 02:40:55.530051 2013] [lbmethod_heartbeat:notice] [pid 2179:tid 140142625933120] AH02282: No slotmem from mod_heartmonitor [Wed Oct 02 02:40:55.541737 2013] [mpm_event:notice] [pid 2179:tid 140142625933120] AH00489: Apache/2.4.6 (Unix) PHP/5.5.1 configured -- resuming normal operations [Wed Oct 02 02:40:55.541768 2013] [core:notice] [pid 2179:tid 140142625933120] AH00094: Command line: '/usr/local/apache2/bin/httpd' [Wed Oct 02 02:42:04.170782 2013] [:error] [pid 2615:tid 140142199158528] [client 192.168.0.81:55732] script '/usr/local/apache2/htdocs/info.php' not found or unable to stat
-
Jenny D over 10 yearsWhat do your logs say?
-
Mehran over 10 yearsI'll update the question.
-
Mehran over 10 yearsWhat's up with the negative vote!?
-
Jenny D over 10 yearsWhich of the servers was the logfile from?
-
Mehran over 10 yearsThe log content belongs to the balancer. I've made sure that the request does not arrive at the back-ends by removing
access_log
anderror_log
files in them and sending a new request. No log file was created for the new request. -
Jenny D over 10 yearsI'm missing the
ProxyPass
line in your config. -
Mehran over 10 yearsThis is my first time setting up a load balancer. Is it OK to add
ProxyPass / balander://pop
? -
Mehran over 10 yearsHaving the
ProxyPass / balander://pop
added, nowerror_log
says:No protocol handler was valid for the URL /info.php. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
with a500 Internal server
error on browser. -
user128296 over 10 yearsYou should try haproxy for load balancing it's easy to configure and have great functionality.
-
Jenny D over 10 yearsUnless
balander
is a typo this may be your problem (in that it should be balancer :-) -
Mehran over 10 yearsThe issue you mentioned was real but even with
ProxyPass / balancer://pop
I still getIf you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
error. Any more suggestions? -
Mehran over 10 yearsIs
mod_proxy_html
needed? Because I don't have that and since I've compiled the Apache myself, it's not that easy to compile a new module. I just hope the lack of this module is not the case! -
Mehran over 10 yearsI fixed it, it should have been
ProxyPass / balancer://pop/
with the slash at the end!!
-
-
Mehran over 10 yearsJust don't forget the
/
at the end ofProxyPass
. Thanks again.