1

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?

1 Answer 1

1

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.

2
  • We forgot the $!=1 initially, but now it works. Thanks!
    – Andomar
    Sep 6, 2010 at 14:42
  • Nice to hear you got it working! :) Sep 7, 2010 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .