NDC & PKI

[Day 5] 7. Squid as a Load Balancer

D
DITISS Admin
••4 min read

Setup Overview

We are configuring SQUID to act as a load balancer for two Apache Servers on separate machines.

Network Configuration:

  • 192.168.80.128: SQUID server (load balancer).
  • 192.168.80.129: Apache Server 1.
  • 192.168.80.130: Apache Server 2.

Objective:

Distribute traffic between the two Apache servers using SQUID in a round-robin manner.


Steps to Set Up SQUID as a Load Balancer

1. Install and Configure SQUID on Machine 192.168.80.128

  1. Make sure you have already configured squid before, if not then visit Day 4 and configure it accordingly. After configuring Squid, follow the steps written below:

  2. Change the Default Port to 80:

    • Open the squid.conf file:

      bash
      sudo nano /etc/squid/squid.conf
      
    • Search for

      3128
      and replace it with
      80
      :

      plaintext
      http_port 80 vhost
      
  3. Configure Load Balancing:

    • Add the following lines to the

      squid.conf
      file:

      plaintext
      cache_peer 192.168.80.129 parent 80 0 no-query originserver round-robin weight=1 name=one
      cache_peer 192.168.80.130 parent 80 0 no-query originserver round-robin weight=1 name=two
      
    • Explanation:

      • cache_peer: Defines backend servers.
      • parent: Indicates that these servers will handle HTTP traffic.
      • round-robin: Distributes traffic equally.
      • weight=1: Ensures equal load distribution.
  4. Restart SQUID:

    • Restart the service to apply changes:

      bash
      sudo systemctl restart squid
      sudo systemctl status squid
      

2. Configure Apache Servers

  1. Setup Apache Server 1 on 192.168.80.129:

    • Install Apache (if not already installed):

      bash
      sudo apt-get install apache2
      
    • Create a unique webpage:

      bash
      echo "Welcome to Apache Server 1" | sudo tee /var/www/html/index.html
      
    • Restart Apache:

      bash
      sudo systemctl restart apache2
      
  2. Setup Apache Server 2 on 192.168.80.130:

    • Install Apache:

      bash
      sudo apt-get install apache2
      
    • Create a different webpage:

      bash
      echo "Welcome to Apache Server 2" | sudo tee /var/www/html/index.html
      
    • Restart Apache:

      bash
      sudo systemctl restart apache2
      

3. Test Load Balancing

  1. Open a browser and enter the IP address of the SQUID server:

    plaintext
    http://192.168.80.128
    
  2. Verify Round-Robin Behavior:

    • Refresh the browser multiple times.
    • You should see outputs alternating between:
      • "Welcome to Apache Server 1"
      • "Welcome to Apache Server 2"

Notes

  • The vhost option in

    http_port 80 vhost
    enables virtual hosting, allowing SQUID to handle traffic destined for multiple backends.

  • Ensure the Apache servers are accessible on port 80.

  • If SQUID doesn’t load balance properly, check the logs for debugging:

    bash
    sudo tail -f /var/log/squid/access.log
    

Read Next

8/26/2026

[Day 5] 8. Monitoring a Remote Linux Machine using Nagios

### **Overview** **Goal:** Set up Nagios to monitor a remote Linux machine using **NCPA** (Nagios Cross-Platform Agent). **Setup:** 1. **N...

8/26/2026

[Day 5] 9. Extra

#### **1. What is an Application Proxy?** An **Application Proxy** acts as an intermediary between the client and the server, facilitating secure c...