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.

We have a slightly irregular web server: it serves user details based on the user's IP address. The user details are stored in several databases; each database stores information about a subset of users. Users have data in only one database. There is one master database which tells you where each user can be found.

Due to external factors, the web server has to be replaced by a dedicated machine for each database. It would be easy to set up a reverse proxy that splits requests between servers. However, the decision which server to forward the request to depends on the entry in the master database.

Is there a reverse proxy server that allows a script to decide which back-end server gets to handle a particular request?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Squid can easily do that with its url_rewrite_program and location_rewrite_program parameters.

For example, create a Perl script like

#!/usr/bin/perl -w

$!=1;
while (<>) {
     s@foo@bar@g;
     print;
}

and save that as /usr/local/bin/mysquidrewriter. The above script would replace all the foo occurrences in the URL as bar. For the actual SQL stuff you of course need to modify this script. :-)

Then add to squid.conf a line like

url_rewrite_program /usr/local/bin/mysquidrewriter

When you restart Squid it starts couple of mysquidrewriter processes background and every URL Squid has to serve will be massaged through them. I have done this many times and it works just perfectly.

share|improve this answer
    
We forgot the $!=1 initially, but now it works. Thanks! –  Andomar Sep 6 '10 at 14:42
    
Nice to hear you got it working! :) –  Janne Pikkarainen Sep 7 '10 at 5:11

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.