More Configuration Details | _ | _ | _ |
INDEX BACK NEXT | _ | _ | _ |
Cache accelerator mode |
Why run an accelerator?
These are some reasons why you might want to run a web accelerator using Squid:
Squid is easier to maintain than a regular httpd since you only have to add pages on the origin server and the mirror will catch up. You might want to put Expires headers in your HTTP responses to make sure that the mirror is not serving stale data.
Anything that requires real intelligence on the part of the web server, such as CGI scripts, will be forwarded on to the origin server.
One disadvantage is that the origin server will not know the original IP address of the clients, except through the X-Forwarded-For HTTP header. This will affect logging and visitor analysis, as well as document protection access control lists. You might want to move this log analysis to your accelerator instead.
Configuring Squid as an Accelerator
To make Squid run in accelerator mode, set the http_port value to the port number you want it to listen to. This is usually the HTTP port, 80. Note that Squid must initially run as root to be able to bind to port 80.
The next step is to select the origin server you want to accelerate. You can make Squid choose one of three methods of operation:
#!/usr/bin/perl
$|=1;
while (<>) {
s@http://192\.168\.0\.1@http://www.domain1.com@;
s@http://192\.168\.0\.2@http://www.domain2.com@;
print;
}
A redirector is required to translate the specified hostname into the origin server. Otherwise, Squid will try to accelerate itself, which is not very useful. Assuming the original hosts are called www and the accelerator is called www2, this script will do the translation:
#!/usr/bin/perl
$|=1;
while (<>) {
s@http://www2.domain1.com@http://www.domain1.com@;
s@http://www2.domain2.com@http://www.domain2.com@;
print;
}
The comments in squid.conf note that this can be a security hole, since Squid does not check the Host value, and be made to load any arbitrary web object, which is not desirable. To protect against this, create an ACL with the dstdomain keyword that will limit the domains honored by the accelerator. For example:
acl okdomains dstdomain domain1.com domain2.com
http_access deny !okdomains
http_access allow all