In the fast-paced world of modern web architecture, ensuring efficient and reliable distribution of incoming traffic is crucial. This is where HAProxy, a powerful open-source load balancer and proxy server, comes into play. HAProxy plays a pivotal role in optimizing resource utilization, enhancing application performance, and ensuring high availability. In this blog post, we’ll explore the ins and outs of HAProxy and its significance in today’s web infrastructure.
HAProxy, which stands for High Availability Proxy, is a versatile software that acts as a reverse proxy and load balancer. It efficiently distributes incoming network traffic across multiple servers, enabling seamless scaling of web applications and services. Whether you’re running a small website or a complex microservices architecture, HAProxy can help maintain stability, enhance performance, and improve fault tolerance.
Key Features and Benefits
Load Balancing: HAProxy excels at distributing incoming requests among multiple backend servers based on various algorithms, such as round-robin, least connections, or source IP affinity. This leads to optimized resource utilization and prevents server overloads.
High Availability: As the name suggests, HAProxy is designed to ensure high availability of services. It can automatically detect server failures and redirect traffic to healthy servers, minimizing downtime and enhancing user experience.
Security: With its ability to perform Layer 7 (application layer) inspection, HAProxy can mitigate various types of attacks, such as Distributed Denial of Service (DDoS) attacks and SQL injection attempts.
SSL/TLS Termination: HAProxy can offload SSL/TLS encryption and decryption, reducing the computational load on backend servers and improving overall performance.
Advanced Traffic Routing: HAProxy supports intricate traffic routing configurations, enabling A/B testing, blue-green deployments, and canary releases. This allows developers to test new features and updates with a subset of users before rolling them out globally.
Logging and Monitoring: HAProxy offers detailed logs that help in diagnosing issues and optimizing configurations. Integration with monitoring tools like Prometheus and Grafana allows for real-time performance monitoring and trend analysis
Client has requirement to access one SAP port publicly for what’s app integration as the server was running in private subnet, they require an ALB to publish the port publicly. But at the same time, clients don’t want additional monthly costs like for ALB or NLB which costs around $17 monthly.
In general Proxy servers are servers that act as intermediaries between clients and servers. When a client/browser requests a resource from a server, the request is first sent to the proxy server, which then forwards the request to the server on behalf of the client. The server then sends the response back to the proxy server, which in turn sends it back to the client. We will configure HAProxy in one publicly available server in our case in existing VPN server.
Getting Started with HAProxy
Installation: HAProxy can be installed on various operating systems. It’s often available through package managers like APT, YUM, or can be compiled from source.
First we need to install haproxy in a separate server by following command;
apt install haproxy -y
Open haproxy.cfg configuration file.
In the configuration file already block of lines present defining error logs, default timeout etc.
Without changing anything Just add following few lines to work as a proxy server for your application server;
frontend haproxy-main bind *:80 mode http default_backend apache_webservers backend apache_webservers balance roundrobin mode http server websvr1 10.0.0.10:80 check server websvr2 10.0.0.20:80 check
(** you can change your frontend and backend server name according to your requirement, Also replace the backend ip of the server to your server ip)