Example Configurations

Let's cover two example setups: one, where you are simply using Squid's accelerator function so that the machine has both a web server and a cache server on port 80; two, where you are using Squid as an accelerator to speed up a slow machine.

Replacing a Combination Web/Cache server

First, let's cover the most common use of accelerator mode: replacing a combination web/cache server with Squid. When Squid is acting as an accelerator (speeding up a slow web server), Squid will accept requests on port 80 (on any IP address) and pass them to a cache server on a different machine (also on port 80). Since it's unlikely that you want to use two machines where you can use one (unless you are changing to Squid due to server overload), we will need to configure Squid to pass requests to the local machine.

Squid will need to accept incoming requests on port 80 (using the http_port option), and pass the requests on to the web server on another port (since only one process can listen for requests on port 80 at a time). I normally get web servers to listen for requests on port 8000.

Since you want Squid to function both as an accelerator and as a cache server, you will need to use the httpd_accel_with_proxy option.

The cache in this example is the local machine: there is almost certainly no reason to cache results from this server. I could have used an extremely conservative refresh_pattern in the below example, but instead I decide to use the no_cache tag: this way I can make use of my predefined acl. The always_direct tag in the below example will be very useful if you have a peer cache: you don't want the request passed on to a peer machine.

Example 9-3. Forwarding Web Requests to a Server on the Same Machine

http_port 80
# forward incoming requests to localhost, port 8000
httpd_accel_host 127.0.0.1
acl acceleratedHost dst 127.0.0.1/255.255.255.255
httpd_accel_port 8000
acl acceleratedPort port 8000
httpd_accel_with_proxy on
acl all src 0.0.0.0/0.0.0.0
acl myNet src 10.0.0.0/255.255.255.0
# we don't want to cache localhost: it's a waste of disk space
no_cache deny acceleratedHost
# we also don't want requests for localhost passed on to a peer
always_direct allow acceleratedHost
# Allow requests when they are to the accelerated machine AND to the
# right port
http_access allow acceleratedHost acceleratedPort
http_access allow myNet
http_access deny all

Accelerating Requests to a Slow Server

When accelerating a slow server, you may find that communicating with peer caches is faster than communicating with the accelerated host. In the following example, we remove all the options that stop Squid from caching the server's results. We also assume that the accelerated host is listening on port 80, since there is no conflict with Squid trying to listen to the same port.

Once you have tested that connecting to Squid brings up the correct pages, you will have to change the DNS entry to point to your cache server.

Example 9-4. Accelerating a Slow Server

http_port 80
# forward incoming requests to 10.0.0.5, port 80
httpd_accel_host 10.0.0.5
acl acceleratedHost dst 10.0.0.5/255.255.255.255
httpd_accel_port 80
acl acceleratedPort port 8000
httpd_accel_with_proxy on
acl all src 0.0.0.0/0.0.0.0
acl myNet src 10.0.0.0/255.255.255.0
# since we want to try get accelerated pages through peers, and we
# want to cache the results, we remove the no_cache and always_direct
# options
# Allow requests when they are to the accelerated machine AND to the
# right port
http_access allow acceleratedHost acceleratedPort
http_access allow myNet
http_access deny all