In this guide we will learn how to install and configure Squid Proxy server on a Rocky Linux 8 server. This guide also works on other RHEL 8 based distros like Alma Linux and Oracle Linux.
Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It runs on most available operating systems.
Squids reverse proxy is a service that sits between the Internet and the webserver (usually within a private network) that redirects inbound client requests to a server where data is stored for easier retrieval. If the caching server (proxy) does not have the cached data, it then forwards the request on to the web server where the data is actually stored. This type of caching allows for the collection of data and reproducing the original data values stored in a different location to provide for easier access.
A reverse proxy typically provides an additional layer of control to smooth the flow of inbound network traffic between your clients and the web server.
When selecting a computer system for use as a dedicated Squid caching proxy server, many users ensure it is configured with a large amount of physical memory (RAM) as Squid maintains an in-memory cache for increased performance.
- How to install and configure Squid Proxy on Alma/Rocky Linux 9
- How to install and configure Squid Proxy on Ubuntu 20.04
- How to install and configure Squid Proxy on Debian 11
- How to install and configure Squid Proxy on OpenSUSE Leap 11
- An updated Rocky Linux 8 server with at least 1GB of RAM
- Root access to the server or user with sudo access
- Access to the internet from the server
Table of Content
- Ensuring that the server is up to date
- Installing squid proxy server
- Starting and enabling the squid service
- Configuring your web browser
- Configuring squid
- Using squid proxy Access Control List (ACL)
- Using Squid to cache web pages
1. Ensuring that the server is up to date
Before proceeding, let us ensure that our server has updated packages. Use this command to achieve that:
sudo dnf update -y
2. Installing Squid proxy server
The packages providing squid proxy server are available in the default Rocky Linux repositories. Install it using this command:
sudo dnf install -y squid
Confirm that the package was installed as expected
$ rpm -qi squid Name : squid Epoch : 7 Version : 4.15 Release : 1.module+el8.5.0+705+218dec94 Architecture: x86_64 Install Date: Mon 17 Jan 2022 07:07:04 PM UTC Group : Unspecified Size : 12402901 License : GPLv2+ and (LGPLv2+ and MIT and BSD and Public Domain) Signature : RSA/SHA256, Tue 09 Nov 2021 11:01:49 PM UTC, Key ID 15af5dac6d745a60 Source RPM : squid-4.15-1.module+el8.5.0+705+218dec94.src.rpm Build Date : Tue 09 Nov 2021 10:50:18 PM UTC Build Host : ord1-prod-x86build004.svc.aws.rockylinux.org Relocations : (not relocatable) Packager : [email protected] Vendor : Rocky URL : http://www.squid-cache.org Summary : The Squid proxy caching server Description : Squid is a high-performance proxy caching server for Web clients, supporting FTP, gopher, and HTTP data objects. Unlike traditional caching software, Squid handles all requests in a single, non-blocking, I/O-driven process. Squid keeps meta data and especially hot objects cached in RAM, caches DNS lookups, supports non-blocking DNS lookups, and implements negative caching of failed requests. Squid consists of a main server program squid, a Domain Name System lookup program (dnsserver), a program for retrieving FTP data (ftpget), and some management and client tools.
3. Starting and enabling the squid service
The squid proxy server will be not started by default in our Rocky Linux 8 system. Start it with this command:
sudo systemctl start squid
To check the status, issue this command:
$ sudo systemctl status squid ● squid.service - Squid caching proxy Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2022-01-17 19:08:32 UTC; 6s ago Docs: man:squid(8) Process: 429390 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS) Main PID: 429396 (squid) Tasks: 3 (limit: 23176) Memory: 13.9M CGroup: /system.slice/squid.service ├─429396 /usr/sbin/squid --foreground -f /etc/squid/squid.conf ├─429398 (squid-1) --kid squid-1 --foreground -f /etc/squid/squid.conf └─429399 (logfile-daemon) /var/log/squid/access.log Jan 17 19:08:32 dev-rockysrv.inv.re systemd: Starting Squid caching proxy... Jan 17 19:08:32 dev-rockysrv.inv.re squid: Squid Parent: will start 1 kids Jan 17 19:08:32 dev-rockysrv.inv.re squid: Squid Parent: (squid-1) process 429398 started Jan 17 19:08:32 dev-rockysrv.inv.re systemd: Started Squid caching proxy.
We can confirm that the service is running from the above command. To ensure that the service starts on boot, use the enable command:
sudo systemctl enable squid
4. Configuration for Your Web Browser
Before you make any changes to the squid configuration file, you have to change some settings in your web browser. So, open your web browser and open “network settings”, then proceed to “proxy settings”. Click on the “manual proxy” configuration, then write the IP_Address of your squid proxy server in the HTTP proxy bar and port no (by default, squid proxy port is 3128). Now, the squid proxy will go through your IP_Address. You can check it by typing any URL in your web browser; it will give you an error saying access denied, and to allow the access, we have to make changes in the squid configuration file.
5. Configuring Squid
The default Squid configuration file is located in the
/etc/squid/ directory, and the main configuration file is called
squid.conf. This file contains the bulk of the configuration directives that can be modified to change the behaviour of Squid. The lines that begin with a
#, are commented out or not read by the file. These comments are provided to explain what the related configuration settings mean.
To edit the configuration file, let’s start by taking a backup of the original file, in case we need to revert any changes if something goes wrong or use it to compare the new file configurations.
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
Now that a copy has been made as a backup file, we can make changes in the “squid.conf” file.
To open “squid.conf” file in vim, type this command:
sudo vim /etc/squid/squid.conf
Go to the line
http_access deny all
Change it to:
http_access allow all
You will have to restart the squid proxy server for the changes to apply. Use this command:
sudo systemctl restart squid
Now, check your web browser again, type any URL, and it should be working.
6. Using squid proxy ACL (Access Control List)
We can also use Squid as to control access to different websites(web traffic) by either allowing or blocking them. To do so, go to the line
acl CONNECT method CONNECT.
And below this line, write the ACL (access control list) to block the websites you want.
acl block_websites dstdomain .facebook.com .youtube.com .instagram.com
Then deny the statement.
http_access deny block_websites
Save the changes, and to check whether your blocked websites are blocked or not, restart your squid service and verify the URL in your web browser.
You can also block a user from downloading specific files like audio and video files using ACL.
acl media_files urlpath_regex -i \.(mp3|mp4|FLV|AVI|MKV)
It will prevent the user from downloading audio or video files with extensions like mp3, mp4, FLV, etc. Add any file extension you want to prevent from downloading. Now, below this line, write the deny statement.
http_access deny media_files
The media files will then be blocked from downloading.
7. Using Squid to Cache web pages
Proxy servers are also used for boosting the network performance by loading the web page faster by caching the website’s data. You can also change the directory location where cached data should be stored. Moreover, you can also change the cache file size and no. of directories in which data would be saved.
To make changes, open
squid.conf file and go to the following line:
#cache_dir ufs /var/spool/squid 100 16 256
This line will be commented by default, so uncomment this line by removing the
In the above line, there is a phrase “100 16 256”. The 100 shows the size of the cache file, and you may change it to any size like 300. 16 shows the number of directories in which the cache file is saved. 256 shows the no. of subdirectories.
cache_dir ufs /var/spool/squid 100 16 256
You can also change the size of the cache file by adding the following line in the “squid.conf” file:
cache_mem 300 MB
If you want to change the path of the cache file directory, create new dir structure using this command:
sudo mkdir -p /path/where/you/want/to/place/file
To change the ownership of the cache directory to squid proxy, you have to execute this command:
sudo chown -R proxy:proxy /path/where/you/want/to/place/file
Now, stop the squid service using this command:
sudo systemctl stop squid
And then run the command with this command to make the missing cache directories in the new cache directory:
sudo squid -z
Now, start the squid service again using the command below:
sudo systemctl start squid
We have managed to install and configure squid proxy server in this guide. Squid proxy is a very good tool that can be used in organizations or by small internet service providers to control web traffic and internet access. It boosts web browsing speed and provides security mechanisms for web traffic.