Setting up Virtual Hosts when using Squid as a web accelerator

There are some additional things you have to do when setting up a virtual host if you are using squid as a web accelerator.
When you are setting up the VirtualHost in Apache you have to make sure that you specify the localhost rather than using the actual IPAddress.

<VirtualHost 127.0.0.1:80&#062

rather than

<VirtualHost 64.65.64.65:80&#062

The reason is that Apache is only listening on port 80 and squid is set up to only allow acceleration for the local host. Therefore you will be denied access by squid if you try to connect to the virtual host on port 80 using anything but what squid thinks is the local host address.

The final step is to tell squid that this host is on 127.0.0.1 as in order to be an accelerator squid has been compiled with --disable-internal-dns so that it looks up dns in the hosts table first. You then have to specify the hosts in the /etc/hosts file like so:

127.0.0.1 myvirtualhost.com

127.0.0.1 myvirtualhost2.com

Once you have done that squid will pass your requests for the virtual domain through to Apache which will then serve the page and depending on your cache headers the page will then be stored in the squid cache.