Squid Proxy Server is a popular proxy server that sits between client browser and your website and allows you to easily cache frequently requested web pages on your site. It improves website speed & performance. In this article, we will look at how to install & configure Squid Proxy Server in CentOS 7. You can also use these steps on Redhat & Fedora Linux systems.
How to Install & Configure Squid Proxy Server
Here are the steps to install & configure squid proxy server.
1. Update Software Repositories
Open terminal and run the following command to update CentOS software repositories.
$ sudo yum -y update
Also read : Extract .bz2 file in Linux
2. Install Squid Package
Run the following command to install Squid Package.
$ yum -y install squid
If you see any prompts during installation, enter Y.
Once Squid server is installed, start it with the following command.
$ sudo systemctl start squid
If you want to automatically start squid at the time of boot, run the following command.
$ sudo systemctl enable squid
If you want to view the status of your squid server, run the following command
$ sudo systemctl status squid
Also read : How to View Hidden Files in Linux
3. Configure Squid Proxy Server
Next, we will configure Squid Proxy Server. Open its configuration file found at /etc/squid/squid.conf using a text editor.
$ sudo vi /etc/squid/squid.conf
Look for the following line
http_port 3128
If you want to change the port to another number, replace 3128 with a port number of your choice. Also, set the proxy mode to transparent if you don’t want the Squid proxy server to change the requests & responses of your website.
http_port 3128 transparent
Please make sure that you have opened port 3128 on your firewall.
By default, Squid Proxy server is configured to block all incoming HTTP traffic using the following line.
http_access deny all
Change it to
http_access allow all
Restart Squid proxy to apply changes.
$ sudo systemctl restart squid
Also read : How to Fix “Undefined Variable” in PHP
4. Configure Squid Client
On your client machine, open your web browser (e.g. Firefox) and go to
Menu > Options > Network Settings > Settings
Select Manual proxy configuration in the displayed window. In the HTTP Proxy textbox, enter the IP address of machine that hosts your proxy server.

Also read : How to Merge Two Dictionaries in Python
At this point, you are good to use Squid Proxy. We have provided some optional configurations, in case you need them.
Create Access Control List (ACL)
If you are unable to access your proxy server from outside its network, then create an access control list. Open Squid Proxy configuration file
$ sudo vi /etc/squid/squid.conf
Add the following line to allow access from 54.43.32.21
acl localnet src
54.43.32.21
You can also allow access from an IP range using CIDR notations
acl localnet src
54.43.32.
0/24
Also read : How to Run PHP Scripts Automatically
Set up basic authentication
Squid also supports basic authentication. Run the following command to install httpd-tools
yum -y install httpd-tools
Once the installation is complete, create new file
$ sudo touch /etc/squid/passwd && chown squid /etc/squid/passwd
Use the following command to create password, replace user_name with your username
htpasswd /etc/squid/passwd user
_name
Enter the password for this new user, when prompted.
Open Squid Proxy configuration file
$ sudo vi /etc/squid/squid.conf
Add the following lines.
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd auth_param basic children 5 auth_param basic realm Squid Basic Authentication auth_param basic credentialsttl 2 hours acl auth_users proxy_auth REQUIRED http_access allow auth_users
Restart Squid Proxy Server to apply changes.
$ sudo systemctl restart squid
Also read : How to Disable Directory Browsing in Apache Server
How to Block Websites using Squid Proxy
Squid proxy also allows you to block specific websites. Create a new file to list blocked websites
$ sudo vi /etc/squid/blocked.acl
Add the websites to be blocked, one per line. Each starting with a dot.
.twitter.com .facebook.com .pinterest.com
Open Squid configuration file
$ sudo vi /etc/squid/squid.conf
Add the following lines above your ACL list
acl blocked_websites dstdomain “/etc/squid/blocked.acl”
http_access deny blocked_websites
Save and close the file. Restart Squid Proxy to apply changes.
$ sudo systemctl restart squid
That’s it. Now your list of specified websites will be blocked.
In this article, we have looked at how to install and configure Squid Proxy server. We have also looked various additional configuration options.
Also read : How to Prevent Direct File Download In Apache