How To Setup and Configure a Proxy Server – Squid Proxy

A proxy server has many use cases. it could range from personal internet access to restrict organization systems/servers to the access the external world or to limit external internet access for a set of servers on the cloud.

The best way to configure a proxy server is using Squid proxy. It is a widely used proxy server.

In this article, we have covered the following.

  1. Install proxy server
  2. Configure the proxy server
  3. Configure basic proxy authentication.

Note: This tutorial is tested on CentOS 7. It should work on all the other related Linux flavors.

Install Proxy Server: Squid Proxy

Step1: Update the server

Step 2: Configure EPEL repo.

Step 3: Install squid

Step 4: Start and enable squid server.

Step 5: Check the status of squid server.

squid server status

Configure Proxy Server: Squid Proxy

All the configurations for squid server are present in /etc/squid/squid.conf file.

Configure proxy Sources To Access Internet

First, you need to configure the sources from which squid proxy should accept connections. For example, you might need to access this proxy server only from your home network or from specific CIDR ranges.

You can add a source IP range with an ACL using the following format.

READ  How to Setup Slaves on Jenkins 2.0 Using Password and ssh Keys

Open  /etc/squid/squid.conffile and add the source add as shown below. Change the IP to the desired network/IP source based on your needs. In the following example, we have added a single source IP.

squid server configuration

Restart the proxy server after making the ACL changes.

Test proxy Server Connectivity

Test if the proxy server is working using a simple curl request. Use the following curl format. By default squid proxy runs on 3128 port.

/Users/bibin/Downloads/squid server connectivity test

Configure Proxy Authentication

Along with access ACL’s, you can add basic authentication to your proxy server for extra security. Follow the steps given below for setting up a basic auth for the squid proxy server.

Step 1: Install httpd-tools

Step 2: Create a passwd file and make squid as the file owner.

Step 3: Add pxuser  to the password file using htpasswd utility. It will prompt for a custom password. Enter a strong password you need. This username and password will be used for all connections through this proxy.

Step 4: Open squid config file.

Add the following to the config file and save it.

Step 5: Now, restart squid server for the configuration changes to take place.

READ  How to Setup AWS ECS Cluster as Build Slave for Jenkins

Step 6: Now if you test the proxy connection using curl, you will get the “authentication required message” as shown below.

Now, test the connectivity with proxy user and password we configured in step 3. An example syntax is shown below.

With username and password, your proxy request should go through.

Blocking Websites

Another great use of the proxy server is restricting the website access. Follow the steps below for creating a block list.

Step 1: Open a blocked list file.

Add the websites to be blocked in the file. For example,

Step 2: Open the squid config file.

Add the following to the ACL list.

Step 3: Restart the squid server.

Now if you try to access the blocked site through the proxy, you will get a forbidden message as shown below.

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.