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?


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

while (<>) {

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.