How To Install Squid Proxy on AlmaLinux 8

In this guide, we intend to teach you How To Install Squid Proxy on AlmaLinux 8.

Squid is a Unix-based proxy server that caches Internet content closer to a requestor than its original point of origin. Squid supports caching of many different kinds of Web objects, including those accessed through HTTP and FTP.

A Squid proxy server is generally installed on a separate server than the Web server with the original files. Squid works by tracking object use over the network. Squid will initially act as an intermediary, simply passing the client’s request on to the server and saving a copy of the requested object. If the same client or multiple clients request the same object before it expires from Squid’s cache, Squid can then immediately serve it, accelerating the download and saving bandwidth.

How To Install Squid Proxy on AlmaLinux 8

Before you start to install Squid Proxy, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our article the Initial Server Setup with AlmaLinux 8.

Also, you need a domain name that pointed to your server’s IP address.

Now you can follow the steps below to install Squid proxy on your server.

Set up and Configure Squid Proxy on AlmaLinux 8

By default, squid is available in the default AlmaLinux repository. First, update your local package index with the following command:

sudo dnf update -y

Then, use the following command to install the Epel repository on your server:

sudo dnf install epel-release

Now you can use the following command to install Squid proxy:

sudo dnf install squid

Verify your installation by checking the Squid version:

squid --version
Output
Squid Cache: Version 4.15
Service Name: squid

Next, start and enable Squid service to start on boot with the following commands:

sudo systemctl start squid.service
sudo systemctl enable squid.service

To check that Squid is active and running on AlmaLinux 8, run the following command:

sudo systemctl status squid.service

In your output you will see:

Output
● squid.service - Squid caching proxy
Loaded: loaded (/usr/lib/systemd/system/squid.service; enabled; vendor pres>
Active: active (running) since Sun 2022-07-24 04:34:40 EDT; 13s ago
Docs: man:squid(8)
Main PID: 91083 (squid)
Tasks: 3 (limit: 11409)
Memory: 15.4M
CGroup: /system.slice/squid.service
├─91083 /usr/sbin/squid --foreground -f /etc/squid/squid.conf
├─91085 (squid-1) --kid squid-1 --foreground -f /etc/squid/squid.co>
└─91086 (logfile-daemon) /var/log/squid/access.log

Now you need to make some configuration changes in the Squid configuration file on your server to allow clients to connect to Squid from outside this server.

Open the file with your favorite text editor, here we use vi:

sudo vi /etc/squid/squid.conf

Find the lines below in the file:

...
http_access allow localhost
... http_access deny all
...

You can change the deny all to allow all and anyone can connect to your proxy server. But it’s not recommended to do that. You can add the line below and define your IP address to connect to the Squid proxy.

You can find your IP address from the What’s My IP?

Then, add the below line above the http_access allow localhost line.

...
acl localnet src your_ip_address
http_access allow localhost
...

When you are done, save and close the file.

Secure Squid Proxy on AlmaLinux 8

At this point, you need to secure your Squid proxy. Squid allows you to create username-password pairs using built-in Linux functionality, as an additional or an alternative step to restricting access to your proxy by IP address.

First, you need to install some utilities from Apache in order to have access to a password generator that squid likes:

sudo dnf -y install httpd-tools

Then, you can use the htpasswd command to generate a password for your new Squid user:

sudo htpasswd -c /etc/squid/passwords your_squid_username

You will be asked to enter a password for your Squid user.

Output
New password:
Re-type new password:
Adding password for user orca

This command will store your username along with a hash of your new password in /etc/squid/passwords, which will be used as an authentication source by Squid.

You can use the following command to see what that looks like:

sudo cat /etc/squid/passwords
Output
orca:$apr1$zBMMD9nW$.pmD2/7/I.PaZiuglijwF/

Now you need to open the Squid configuration file on AlmaLinux 8 again with your favorite text editor, here we use vi:

sudo vi /etc/squid/squid.conf

Add the following directives after the ports’ ACLs.

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

When you are done, save and close the file.

To apply the changes, restart your Squid service on AlmaLinux 8:

sudo systemctl restart squid.service

We assumed that you have enabled the firewalld. Now you need to open port 3128 through the firewall with the following command:

sudo firewall-cmd --add-service=squid --permanent

Reload the firewall to apply the new rules:

sudo firewall-cmd --reload

How To Connect through Squid Proxy

To display your Squid server, you can use the curl command on AlmaLinux 8. To do this, run the following command:

curl -v -x http://your_squid_username:your_squid_password@your_server_ip:3128 http://www.google.com/

In your output you will see:

Output
* Trying server-ip:3128...
* TCP_NODELAY set
* Connected to server-ip (server-ip) port 3128 (#0)
* Proxy auth using Basic with user 'orca'
> GET http://www.google.com/ HTTP/1.1
...

Also, you can access HTTPs sites with your Squid proxy without any configuration changes.

curl -v -x http://your_squid_username:your_squid_password@your_server_ip:3128 https://www.google.com/

In your output you will see:

Output
* Trying server-ip:3128...
* TCP_NODELAY set
* Connected to server-ip (server-ip) port 3128 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to www.google.com:443
* Proxy auth using Basic with user 'orca'
> CONNECT www.google.com:443 HTTP/1.1
> Host: www.google.com:443
> Proxy-Authorization: Basic b3JjYTpvcmNhMTIz
> User-Agent: curl/7.68.0
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 200 Connection established
<
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!

For more information about Squid proxy, you can visit the Squid Documentation page.

Conclusion

At this point, you learn to Install Squid Proxy on AlmaLinux 8.

Hope you enjoy it.

You may be interested in these articles:

Install and Configure XAMPP on AlmaLinux 8

Install and Configure Varnish Cache for Apache on AlmaLinux 8

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular