Link to home
Start Free TrialLog in
Avatar of bisonfur37
bisonfur37

asked on

mod_rewrite load balancing - but mod_rewrite isn't taking.

I am trying to use mod_rewrite to load balance an indefinite number of web servers, using the explanation provided by the Apache Group at http://www.engelschall.com/pw/apache/rewriteguide/#ToC29

I copied the description they gave in the article verbatim, only changing the specifics concerning my servers in the perl script (they are on IPs instead of DNS names, and there are less of them). Then I took their httpd.conf description and applied them (again, verbatim) to the httpd.conf file, only changing the location of the perl script. Now, from what I understand of mod_rewrite (which isn't much, I'll admit), the RewriteRule should be taking, and sending me to alternate servers. However, all that the "connection" server does is show the default index page I have on it.

Specifics:
1) RedHat Linux, v9.0 running Apache 2.0.40
2) Location of perl program /var/www/iscripts/loadbalance.pl
3) I have 2 boxes set up. One runs 2 virtual servers, each running off their own IP (through eth aliasing). Both of those virtual servers are running fine and dandy. I can connect perfectly to them. The other is running only the version of Apache with mod_rewrite.
4) The way I am running the servers, one is connected to the other with a crossover cable. While this may be the problem, I highly doubt it. Both can see each other no-problem. (SSH, connecting to the actual Apache servers, etc... all of it works)

I have analyzed everything that I could. There are no typos in any of the configuration files, the perl script works as it should (no bugs).... I am lost. The only thing that I can think of that I havn't tried is using the RewriteLock directive, but I don't know how it's supposed to be used, and I can't find an example of it.

Any help that you guys can give would be highly appreciated. Thanks!
Avatar of ahoffmann
ahoffmann
Flag of Germany image

are you shure that thedb.pl script is called by apache, and that it returns status 0?
If in doubt, add some debugging output to a file in the script.
Avatar of bisonfur37
bisonfur37

ASKER

From what I can tell, the program is not supopsed to exit, it is supposed to continuously run in the background... but I'll take your advice about the debugging output, to ensure that it runs.

OK, this is odd. I perfomred the debugging output like you asked, and the stranges thing happened... all of a sudden, it started working. After that, I removed the debugging output, and it continued.

My question now becomes: what could have caused such erratic behavior?
Alright, so I figured out what was causing the problems yesterday. The RewriteRule on the Apache URL Rewriting Guide (link in the origional question) uses the proxy "[P]" flag at the end of the rule. when I remove that flag, the "connection" server redirects to the other servers.

Unfortunately, this is not the behavior I want to use; I want to use the "connection" server as a proxy to the other servers. This will allow me to keep the "serving" webservers in a "trusted zone", and use the "connection" server as a bastion host/etc.

So, is there some additional directive, or a change in the rule, that I have to add to my httpd.conf file to make it actually work with the [P] flag?
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I figured out the problem... it turns out that in the URL Rewriting Guide, there is an error in the regular expression that I passed over.

The RewriteRule directive's regular expression should read:
  $/(.*)^
Or:
  $(.+)^
Not:
  $/(.+)^
hmm, you mean
  ^(.+)$