Hello.
Let’s see how to install a proxy server like Squid with web cache.
Installation
apt-get install squid
Simple, right?
All the configuration is missing, the file of which we can find in /etc/squid/squid.conf
sudo vi /etc/squid/squid.conf
First of all, we need to enable our network, so under the string
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
we insert the acl called “mynetwork” with the static IP address of the computer from which we want to use the server:
acl mynetwork src ip_address
and enable it by inserting under the string
http_access allow localhost
the string
http_access allow mynetwork
Optionally, we could disable all localnet acls by commenting them out (#).
If the address is dynamic or we want to insert a range of addresses, “ip_address” can be replaced with the network address and its subnet mask (example 192.168.0.0/24) or by specifying all addresses (example 192.168.0.2/192.168.0.3/192.168.0.4).
To disable the “forwarding” of the IP, search for the string
# forwarded_for on
remove the comment and set it to off.
To change the server port, search for the string
http_port 3128
and change 3128 to the port you desire.
To restart the server
service squid restart
Let’s move on to the cache side.
You can easily use the default settings, but if you have a Raspberry (and you’re following the guide for this reason), you might need to use a USB stick or an external hard drive to use as cache.
The file system I recommend for this partition is XFS
sudo apt-get install xfsprogs sudo mkfs.xfs /dev/sda1
With the first command, you’ll install what’s necessary to format in XFS, with the second you’ll format the sda1 partition in XFS. Needless to say, you’ll need to check the name corresponding to the partition of the hard drive you want to format (with sudo fdisk -l).
Once formatted, we’ll insert the UUID of the partition in the “fstab” file so as to mount that partition always in the same folder.
To find the UUID
sudo blkid
Once you’ve found the UUID corresponding to the partition of interest, go edit the /etc/fstab file
sudo vi /etc/fstab
inserting this string
UUID=partition_uuid /mnt/squidcache xfs defaults,noatime 0 0
create the “squidcache” folder in /mnt and assign the right permissions (user_name and group might be “proxy” and “proxy”)
sudo mkdir -p /mnt/squidcache sudo chown -hR user_name:group /mnt/squidcache
and mount everything
sudo mount -a
Having prepared the partition we’ll use as web cache, let’s enable it in Squid by uncommenting
cache_dir ufs /var/spool 1000 16 256
and changing “/var/spool” to “/mnt/squidcache” (in case we don’t want to use a different partition, leave it as is) while leaving the other parameters unchanged (16 and 256).
Also uncomment
# cache_effective_user nouser
and change “nouser” to the user_name used when we changed the permissions of the “squidcache” folder (so that Squid can write).
Finally, uncomment
maximum_object_size valueMB
where value is the maximum value in MB of the file to save in cache.
Restart everything
service squid restart
Bye!
! :) !