How to Implement Redirects in Squid
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.
EditSteps
-
1Write 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 -
2In 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
-
3Make sure that the variable httpd_accel_uses_host_header is set to on or nothing will be redirected.
-
4Reload 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!
homesteading?

gleeking?

computers?

Adobe Photoshop?

EditSources and Citations
Article Info
Categories: Website Maintenance
Thanks to all authors for creating a page that has been read 30,668 times.
About this wikiHow