Edit Article

Squid can be used as a reverse proxy to load balance several web servers instead of using a hardware load balancer. This is useful because Squid can cache a lot of the content coming from the source web servers, thereby reducing their load. However, it isn't quite obvious how to create an Apache style redirect where all hostnames other than the root domain get redirected to www.hostname.com. One way to accomplish this is using a re director program, as shown below.

Ad

EditSteps

  1. 1
    Write a simple redirector program such as the following using Perl:
    #!/usr/bin/env perl
    $|=1;
    while (<>) {
      $url = m/^([^ ]*)/;
      if ($url !~ /^http:\/\/www\.hostname\.com/) {
        $url =~ s@^http://www\.hostname\.com/(.*)@http://www.hostname.com/\1@;
        print "301:$url\n";
      } else {
        print "$url\n";
      }
    }
    
    Ad
  2. 2
    In your squid.conf file change the redirect_program variable, it's probably commented out, and specify where your redirector_program is, ex: /usr/sbin/redirect.pl

  3. 3
    Make sure that the variable httpd_accel_uses_host_header is set to on or nothing will be redirected.
  4. 4
    Reload the squid configuration. You'll need to know the path to the squid executable. Depending on your operating system and installation, it's most likely at /usr/local/squid/sbin/squid. Execute this command on the terminal:
    /usr/local/squid/sbin/squid -k reconfigure
    
    Ad

We could really use your help!

Can you tell us about
homesteading?
Yes
No
homesteading
homesteading your home
Can you tell us about
gleeking?
Yes
No
gleeking
how to gleek
Can you tell us about
computers?
Yes
No
computers
how to dock a laptop
Can you tell us about
Adobe Photoshop?
Yes
No
Adobe Photoshop
how to swap faces in Photoshop
Thanks for helping! Please tell us everything you know about
...
Tell us everything you know here. Remember, more detail is better.
Tips
Provide Details.
Please be as detailed as possible in your explanation. Don't worry about formatting! We'll take care of it. For example:
Don't say: Eat more fats.
Do say: Add fats with some nutritional value to the foods you already eat. Try olive oil, butter, avocado, and mayonnaise.

Article Info

Categories: Website Maintenance

Thanks to all authors for creating a page that has been read 30,668 times.

Did this article help you?
Yes No

Become
an Author!

Write an Article