Here's a step-by-step guide to setting up a proxy server using Squid (for caching and content filtering) and HAProxy (for load balancing and reverse proxying).
Prerequisites
- Server: You'll need a dedicated server or a virtual machine (VM) with a compatible operating system (e.g., Ubuntu, CentOS, or Debian).
- Basic networking knowledge: Understand IP addresses, ports, and network protocols (HTTP, HTTPS, TCP, etc.).
- Text editor or terminal access: For configuring files and executing commands.
Option 1: Squid Proxy Server (Caching and Content Filtering)
Install Squid
- On Ubuntu/Debian: sudo apt update && sudo apt install squid
- On CentOS/RHEL: sudo yum install squid
Configure Squid
- Open the configuration file: sudo nano /etc/squid/squid.conf
- Set the proxy port (default is 3128): http_port 3128
- Define your network (e.g., allow traffic from a specific IP range): acl our_network src 192.168.1.0/24
- Allow HTTP and HTTPS traffic: http_access allow our_network
- Save and close the file
Start and enable Squid
sudo service squid start (or sudo systemctl start squid on systemd-based systems)
sudo service squid enable (or sudo systemctl enable squid on systemd-based systems)
Test your Squid proxy
- Configure your browser to use the proxy server (IP address and port 3128)
- Verify that the proxy is working by checking the Squid access logs: sudo squid -k debug (then check the logs with sudo tail -f /var/log/squid/access.log)
Option 2: HAProxy Proxy Server
Install HAProxy
- On Ubuntu/Debian: sudo apt update && sudo apt install haproxy
- On CentOS/RHEL: sudo yum install haproxy
Configure HAProxy
- Open the configuration file: sudo nano /etc/haproxy/haproxy.cfg
- Set the proxy mode (e.g., http): mode http
- Define a frontend (listen on a port, e.g., 80): frontend http
bind *:80
- Define a backend (e.g., a web server with IP address and port): backend webserver
- server webserver1 192.168.1.100:80 check
- Save and close the file
Start and enable HAProxy
sudo service haproxy start (or sudo systemctl start haproxy on systemd-based systems)
sudo service haproxy enable (or sudo systemctl enable haproxy on systemd-based systems)
Test your HAProxy setup
- Access the proxy server's IP address (and port 80) in your browser
- Verify that the request is forwarded to the backend server (check the web server's access logs)
Alternative Tools
- NGINX: A popular web server that can also act as a reverse proxy and load balancer.
- Pound: A reverse proxy and load balancer with a focus on HTTPS support.
- Apache HTTP Server with mod_proxy: The Apache web server can be configured as a reverse proxy using the mod_proxy module.
- Docker-based solutions: Use pre-configured Docker images for proxy servers like Squid, HAProxy, or NGINX.
- Cloud-based proxy services: Consider managed proxy services like AWS Elastic Load Balancer, Google Cloud Load Balancing, or Cloudflare