Installing Squid on Ubuntu 14.04 as Caching Proxy Server


Squid is a popular caching proxy for web servers that can reduce network bandwidth and improve application response times. Squid optimizes web traffic by caching frequently requests content to memory, freeing your web servers from having to reprocess requests. Since the request is served from Squid’s memory instead of being reprocessed, requests are returned much quicker allowing your web server to handle much more load.

To see where the caching proxy fits in, review the figure below. You’ll notice that web caching servers, like Squid, sit in front of your web application servers.

Web infrastructure: Squid caching servers

The reason for this is so your caching server can capture all requests before they land on your web servers. Any requests returned from the backend web servers will automatically be cached by Squid, since all traffic must return through Squid to the user’s web browser. Requests already cached will be returned directly from Squid’s memory.

Installing Squid

Installing Squid using Aptitude (Easy)

Unless you want bleeding edge features only found in more recent version, you will more than likely use this method for installation. In production environments stability usually trumps features.

  1. Log on to your Ubuntu server with an account that has administrative rights.
  2. Install Squid
    sudo apt-get install -y squid3


Installing Squid from Source (Advanced)

Sometimes you need bleeding edge and stability isn’t as important. For this, you will have to compile your own copy of Squid.

  1. Download the latest ‘stable’ release from Squid’s website.
  2. Install packages needed to compile Squid.
    sudo aptitude build-dep squid3
  3. Extract the downloaded tar file
    tar xvf squid-.tar.gz
  4. Change into the newly created directory.
    cd squid-/
  5. Prepare the source to be compiled on your server.
    ./configure --prefix=/usr --localstatedir=/var --libexecdir=${prefix}/lib/squid --datadir=${prefix}/share/squid --sysconfdir=/etc/squid --with-default-user=proxy --with-logdir=/var/log --with-pidfile=/var/run/ --with-openssl --enable-icmp
  6. Compile the Squid.
  7. Install the newly compiled copy Squid
    make install

Configuring Squid

How you configure Squid is ultimately determined by your web infrastructure – is your entire application hosted on a single web server or do different servers handle different parts of your application? For this example, our web application (WordPress) will be hosted entirely on one server.