{"id":9212,"date":"2024-09-04T16:02:45","date_gmt":"2024-09-04T16:02:45","guid":{"rendered":"https:\/\/www.webhi.com\/how-to\/?p=9212"},"modified":"2024-09-04T16:02:47","modified_gmt":"2024-09-04T16:02:47","slug":"load-balancing-haproxy-ubuntu-linux","status":"publish","type":"post","link":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/","title":{"rendered":"Load Balancing with HAProxy on Ubuntu"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en.jpg\" alt=\"install setup config guide HAProxy load balancing Configure on Ubuntu Debian\" class=\"wp-image-9228\" srcset=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en.jpg 1200w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en-300x169.jpg 300w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en-1024x576.jpg 1024w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en-768x432.jpg 768w, https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en-150x84.jpg 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-introduction\">1. Introduction<\/h2>\n\n\n\n<p>In today&#8217;s digital landscape, ensuring high availability and optimal performance of web applications is crucial. As traffic to your website or application grows, a single server may not be sufficient to handle the load efficiently. This is where load balancing comes into play, and HAProxy stands out as one of the most powerful and flexible load balancing solutions available.<\/p>\n\n\n\n<p>This comprehensive tutorial will guide you through the process of setting up and configuring HAProxy on Ubuntu to distribute incoming traffic across multiple backend servers. By the end of this guide, you&#8217;ll have a robust load balancing solution that can significantly improve your application&#8217;s performance, reliability, and scalability.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-understanding-load-balancing\">2. Understanding Load Balancing<\/h2>\n\n\n\n<p>Before diving into the technical details, let&#8217;s briefly explore what load balancing is and why it&#8217;s essential.<\/p>\n\n\n\n<p>Load balancing is the process of distributing incoming network traffic across multiple servers. This approach offers several benefits:<\/p>\n\n\n\n<ol>\n<li><strong>Improved Performance<\/strong>: By spreading the load across multiple servers, you can reduce the burden on any single server, leading to faster response times.<\/li>\n\n\n\n<li><strong>High Availability<\/strong>: If one server fails, the load balancer can redirect traffic to the remaining healthy servers, ensuring your application remains available.<\/li>\n\n\n\n<li><strong>Scalability<\/strong>: As your traffic grows, you can easily add more servers to your backend pool to handle the increased load.<\/li>\n\n\n\n<li><strong>Flexibility<\/strong>: Load balancers allow you to perform maintenance on backend servers without downtime by temporarily removing them from the pool.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-what-is-haproxy\">3. What is HAProxy?<\/h2>\n\n\n\n<p>HAProxy (High Availability Proxy) is a free, open-source load balancing and proxying solution for TCP and HTTP-based applications. It&#8217;s known for its speed and efficiency, capable of handling millions of connections per second.<\/p>\n\n\n\n<p>Key features of HAProxy include:<\/p>\n\n\n\n<ul>\n<li>Layer 4 (TCP) and Layer 7 (HTTP) load balancing<\/li>\n\n\n\n<li>SSL\/TLS termination<\/li>\n\n\n\n<li>Health checking of backend servers<\/li>\n\n\n\n<li>Advanced logging and statistics<\/li>\n\n\n\n<li>Content-based routing<\/li>\n\n\n\n<li>Rate limiting and DDoS protection<\/li>\n<\/ul>\n\n\n\n<p>Now that we understand the basics, let&#8217;s move on to the practical implementation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-setting-up-the-environment\">4. Setting Up the Environment<\/h2>\n\n\n\n<p>For this tutorial, we&#8217;ll assume you&#8217;re working with Ubuntu 20.04 LTS. You&#8217;ll need:<\/p>\n\n\n\n<ul>\n<li>A Ubuntu 20.04 server with root or sudo access<\/li>\n\n\n\n<li>At least two backend web servers (we&#8217;ll use Apache in this tutorial)<\/li>\n\n\n\n<li>Basic knowledge of the Linux command line<\/li>\n<\/ul>\n\n\n\n<p>Make sure your system is up to date before proceeding:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt update\n$ sudo apt upgrade<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-installing-haproxy\">5. Installing HAProxy<\/h2>\n\n\n\n<p>Installing HAProxy on Ubuntu is straightforward. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt install haproxy<\/code><\/pre>\n\n\n\n<p>After the installation is complete, you can verify the installed version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ haproxy -v<\/code><\/pre>\n\n\n\n<p>You should see output similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">HAProxy version 2.4.24-0ubuntu0.22.04.1 2023\/10\/31<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-configuring-haproxy\">6. Configuring HAProxy<\/h2>\n\n\n\n<p>HAProxy&#8217;s main configuration file is located at&nbsp;<code>\/etc\/haproxy\/haproxy.cfg<\/code>. Before making changes, it&#8217;s a good practice to backup the original configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo cp \/etc\/haproxy\/haproxy.cfg \/etc\/haproxy\/haproxy.cfg.bak<\/code><\/pre>\n\n\n\n<p>Now, let&#8217;s create a basic configuration. Open the file with your preferred text editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo nano \/etc\/haproxy\/haproxy.cfg<\/code><\/pre>\n\n\n\n<p>Replace the contents with the following basic configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">global\n    log \/dev\/log local0\n    log \/dev\/log local1 notice\n    chroot \/var\/lib\/haproxy\n    stats socket \/run\/haproxy\/admin.sock mode 660 level admin expose-fd listeners\n    stats timeout 30s\n    user haproxy\n    group haproxy\n    daemon\n\ndefaults\n    log global\n    mode http\n    option httplog\n    option dontlognull\n    timeout connect 5000\n    timeout client  50000\n    timeout server  50000\n\nfrontend http_front\n    bind *:80\n    stats uri \/haproxy?stats\n    default_backend http_back\n\nbackend http_back\n    balance roundrobin\n    server web1 10.0.0.1:80 check\n    server web2 10.0.0.2:80 check<\/code><\/pre>\n\n\n\n<p>This configuration sets up a basic HTTP load balancer. We&#8217;ll explain each section in detail later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7-setting-up-backend-servers\">7. Setting Up Backend Servers<\/h2>\n\n\n\n<p>For this tutorial, we&#8217;ll assume you have two web servers running Apache. If you haven&#8217;t set them up yet, you can do so with these commands on each server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo apt install apache2\n$ sudo systemctl start apache2\n$ sudo systemctl enable apache2<\/code><\/pre>\n\n\n\n<p>To differentiate between the servers, you might want to customize the default Apache page. On each server, edit the&nbsp;<code>\/var\/www\/html\/index.html<\/code>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo nano \/var\/www\/html\/index.html<\/code><\/pre>\n\n\n\n<p>Replace the content with a simple identifier, like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"markup\" class=\"language-markup\">&lt;h1&gt;Welcome to Web Server 1&lt;\/h1&gt;<\/code><\/pre>\n\n\n\n<p>(Adjust the number for each server)<\/p>\n\n\n\n<p>Make sure to note down the IP addresses of your backend servers and update the&nbsp;<code>haproxy.cfg<\/code>&nbsp;file accordingly in the&nbsp;<code>backend http_back<\/code>&nbsp;section.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8-haproxy-configuration-file-explained\">8. HAProxy Configuration File Explained<\/h2>\n\n\n\n<p>Let&#8217;s break down the HAProxy configuration file we created earlier:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"global-section\">Global Section<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">global\n    log \/dev\/log local0\n    log \/dev\/log local1 notice\n    chroot \/var\/lib\/haproxy\n    stats socket \/run\/haproxy\/admin.sock mode 660 level admin expose-fd listeners\n    stats timeout 30s\n    user haproxy\n    group haproxy\n    daemon<\/code><\/pre>\n\n\n\n<p>This section defines global parameters:<\/p>\n\n\n\n<ul>\n<li><code>log<\/code>: Specifies where to send logs<\/li>\n\n\n\n<li><code>chroot<\/code>: Changes the root directory to improve security<\/li>\n\n\n\n<li><code>stats socket<\/code>: Creates a UNIX socket for runtime commands<\/li>\n\n\n\n<li><code>user<\/code>&nbsp;and&nbsp;<code>group<\/code>: Sets the user and group under which HAProxy runs<\/li>\n\n\n\n<li><code>daemon<\/code>: Runs HAProxy in the background<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"defaults-section\">Defaults Section<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">defaults\n    log global\n    mode http\n    option httplog\n    option dontlognull\n    timeout connect 5000\n    timeout client  50000\n    timeout server  50000<\/code><\/pre>\n\n\n\n<p>This section sets default parameters for all other sections:<\/p>\n\n\n\n<ul>\n<li><code>mode http<\/code>: Sets the default mode to HTTP (layer 7) load balancing<\/li>\n\n\n\n<li><code>option httplog<\/code>: Enables HTTP logging<\/li>\n\n\n\n<li><code>option dontlognull<\/code>: Disables logging of null connections<\/li>\n\n\n\n<li><code>timeout<\/code>: Sets various timeout values<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"frontend-section\">Frontend Section<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">frontend http_front\n    bind *:80\n    stats uri \/haproxy?stats\n    default_backend http_back<\/code><\/pre>\n\n\n\n<p>This section defines how requests should be handled:<\/p>\n\n\n\n<ul>\n<li><code>bind *:80<\/code>: Listens on all interfaces on port 80<\/li>\n\n\n\n<li><code>stats uri<\/code>: Enables the statistics page at the specified URI<\/li>\n\n\n\n<li><code>default_backend<\/code>: Specifies the default backend to use<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"backend-section\">Backend Section<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">backend http_back\n    balance roundrobin\n    server web1 10.0.0.1:80 check\n    server web2 10.0.0.2:80 check<\/code><\/pre>\n\n\n\n<p>This section defines the backend servers:<\/p>\n\n\n\n<ul>\n<li><code>balance roundrobin<\/code>: Uses the round-robin load balancing algorithm<\/li>\n\n\n\n<li><code>server<\/code>: Defines each backend server with its IP and port<\/li>\n\n\n\n<li><code>check<\/code>: Enables health checks on the servers<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9-testing-the-load-balancer\">9. Testing the Load Balancer<\/h2>\n\n\n\n<p>After configuring HAProxy, restart the service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo systemctl restart haproxy<\/code><\/pre>\n\n\n\n<p>You can check the status to ensure it&#8217;s running without errors:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo systemctl status haproxy<\/code><\/pre>\n\n\n\n<p>Now, you can test your load balancer by accessing it through a web browser or using curl:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ curl http:\/\/your_haproxy_ip<\/code><\/pre>\n\n\n\n<p>Repeat this command multiple times. You should see responses alternating between your backend servers, demonstrating that the load balancer is working.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"10-monitoring-and-statistics\">10. Monitoring and Statistics<\/h2>\n\n\n\n<p>HAProxy provides a built-in statistics page that offers valuable insights into your load balancing setup. We&#8217;ve already enabled it in our configuration with the line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">stats uri \/haproxy?stats<\/code><\/pre>\n\n\n\n<p>To access the statistics page, open a web browser and navigate to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">http:\/\/your_haproxy_ip\/haproxy?stats<\/code><\/pre>\n\n\n\n<p>This page provides real-time information about your frontend and backend servers, including:<\/p>\n\n\n\n<ul>\n<li>Server status (UP\/DOWN)<\/li>\n\n\n\n<li>Current sessions<\/li>\n\n\n\n<li>Bytes in\/out<\/li>\n\n\n\n<li>Request rates<\/li>\n\n\n\n<li>Response times<\/li>\n<\/ul>\n\n\n\n<p>You can use this information to monitor the health and performance of your load balancing setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"11-advanced-haproxy-features\">11. Advanced HAProxy Features<\/h2>\n\n\n\n<p>HAProxy offers many advanced features for fine-tuning your load balancing setup. Here are a few you might find useful:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ssl-termination\">SSL Termination<\/h3>\n\n\n\n<p>To handle HTTPS traffic, you can configure HAProxy to perform SSL termination. This offloads the SSL processing from your backend servers. Here&#8217;s an example configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">frontend https_front\n    bind *:443 ssl crt \/etc\/ssl\/certs\/mycert.pem\n    reqadd X-Forwarded-Proto:\\ https\n    default_backend http_back<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sticky-sessions\">Sticky Sessions<\/h3>\n\n\n\n<p>If your application requires session persistence, you can enable sticky sessions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">backend http_back\n    balance roundrobin\n    cookie SERVERID insert indirect nocache\n    server web1 10.0.0.1:80 check cookie server1\n    server web2 10.0.0.2:80 check cookie server2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"health-checks\">Health Checks<\/h3>\n\n\n\n<p>HAProxy can perform more advanced health checks. For example, to check if a specific URL returns a 200 status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">backend http_back\n    balance roundrobin\n    option httpchk GET \/health.php\n    http-check expect status 200\n    server web1 10.0.0.1:80 check\n    server web2 10.0.0.2:80 check<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"rate-limiting\">Rate Limiting<\/h3>\n\n\n\n<p>To protect your servers from abuse, you can implement rate limiting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">frontend http_front\n    bind *:80\n    stick-table type ip size 100k expire 30s store http_req_rate(10s)\n    http-request track-sc0 src\n    http-request deny deny_status 429 if { sc_http_req_rate(0) gt 100 }\n    default_backend http_back<\/code><\/pre>\n\n\n\n<p>This configuration limits each IP to 100 requests per 10 seconds.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"12-troubleshooting-common-issues\">12. Troubleshooting Common Issues<\/h2>\n\n\n\n<p>When working with HAProxy, you might encounter some common issues. Here&#8217;s how to troubleshoot them:<\/p>\n\n\n\n<ol>\n<li><strong>Configuration Errors<\/strong>: Always check your configuration for syntax errors before restarting HAProxy:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ haproxy -c -f \/etc\/haproxy\/haproxy.cfg<\/code><\/pre>\n\n\n\n<ol start=\"2\">\n<li><strong>Backend Servers Down<\/strong>: Check the HAProxy stats page to see if any backend servers are marked as DOWN. Verify that your backend servers are running and accessible.<\/li>\n\n\n\n<li><strong>Connectivity Issues<\/strong>: Ensure that HAProxy can reach your backend servers. Check firewall rules and network configurations.<\/li>\n\n\n\n<li><strong>SSL Certificate Problems<\/strong>: If you&#8217;re using SSL termination, make sure your certificates are valid and properly configured.<\/li>\n\n\n\n<li><strong>Logging<\/strong>: Enable detailed logging to troubleshoot issues:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">global\n    log \/dev\/log local0 debug<\/code><\/pre>\n\n\n\n<p>Then check the logs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">$ sudo tail -f \/var\/log\/haproxy.log<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"13-best-practices-and-security-considerations\">13. Best Practices and Security Considerations<\/h2>\n\n\n\n<p>To ensure optimal performance and security of your HAProxy setup, consider the following best practices:<\/p>\n\n\n\n<ol>\n<li><strong>Regular Updates<\/strong>: Keep HAProxy and your backend servers updated with the latest security patches.<\/li>\n\n\n\n<li><strong>Secure Communication<\/strong>: Use SSL\/TLS for all communications, including between HAProxy and backend servers.<\/li>\n\n\n\n<li><strong>Access Control<\/strong>: Implement IP whitelisting or authentication for sensitive areas like the statistics page.<\/li>\n\n\n\n<li><strong>Monitoring<\/strong>: Set up monitoring and alerting for HAProxy and your backend servers.<\/li>\n\n\n\n<li><strong>Backup Configuration<\/strong>: Regularly backup your HAProxy configuration file.<\/li>\n\n\n\n<li><strong>Rate Limiting<\/strong>: Implement rate limiting to protect against DDoS attacks.<\/li>\n\n\n\n<li><strong>Logging<\/strong>: Configure comprehensive logging for troubleshooting and security analysis.<\/li>\n\n\n\n<li><strong>Separate User<\/strong>: Run HAProxy under a separate, non-root user for improved security.<\/li>\n\n\n\n<li><strong>TCP Keepalives<\/strong>: Enable TCP keepalives to detect and remove dead connections:<code>option tcpka<\/code><\/li>\n\n\n\n<li><strong>Regular Testing<\/strong>: Periodically test your load balancing setup, including failover scenarios.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"14-conclusion\">14. Conclusion<\/h2>\n\n\n\n<p>In this comprehensive tutorial, we&#8217;ve covered the essentials of setting up and configuring HAProxy as a load balancer on Ubuntu. We&#8217;ve explored basic and advanced configurations, troubleshooting techniques, and best practices for maintaining a robust and secure load balancing solution.<\/p>\n\n\n\n<p>HAProxy&#8217;s flexibility and powerful features make it an excellent choice for improving the performance, reliability, and scalability of your web applications. As you become more familiar with HAProxy, you&#8217;ll discover even more ways to optimize your infrastructure to meet your specific needs.<\/p>\n\n\n\n<p>Remember that load balancing is just one part of building a scalable and resilient web application. Consider combining HAProxy with other tools and practices, such as containerization, automated deployments, and comprehensive monitoring, to create a truly robust and efficient web infrastructure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In today&#8217;s digital landscape, ensuring high availability and optimal performance of web applications is crucial. As traffic to your website or application grows, a single server may not be sufficient to handle the load efficiently. This is where load balancing comes into play, and HAProxy stands out as one of the most powerful ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[182,4],"tags":[],"yoast_head":"\n<title>Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations<\/title>\n<meta name=\"description\" content=\"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"WebHi Tutorials &amp; Documentations\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webhi.technology\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-04T16:02:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-04T16:02:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en.jpg\" \/>\n<meta name=\"author\" content=\"webhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:site\" content=\"@WebHiTechnology\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\"},\"author\":{\"name\":\"webhi\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\"},\"headline\":\"Load Balancing with HAProxy on Ubuntu\",\"datePublished\":\"2024-09-04T16:02:45+00:00\",\"dateModified\":\"2024-09-04T16:02:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\"},\"wordCount\":1304,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"articleSection\":[\"Virtualization &amp; Cloud computing\",\"Web servers\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\",\"name\":\"Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations\",\"isPartOf\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\"},\"datePublished\":\"2024-09-04T16:02:45+00:00\",\"dateModified\":\"2024-09-04T16:02:47+00:00\",\"description\":\"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webhi.com\/how-to\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Load Balancing with HAProxy on Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#website\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"name\":\"WebHi Tutorials &amp; Documentations\",\"description\":\"System administration and knowledge base\",\"publisher\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#organization\",\"name\":\"WebHi Technology\",\"url\":\"https:\/\/www.webhi.com\/how-to\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png\",\"width\":288,\"height\":95,\"caption\":\"WebHi Technology\"},\"image\":{\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webhi.technology\",\"https:\/\/twitter.com\/WebHiTechnology\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54\",\"name\":\"webhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435\",\"contentUrl\":\"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435\",\"caption\":\"webhi\"},\"sameAs\":[\"https:\/\/www.webhi.com\/how-to\"],\"url\":\"https:\/\/www.webhi.com\/how-to\/author\/webhi\/\"}]}<\/script>\n","yoast_head_json":{"title":"Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations","description":"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/","og_locale":"en_US","og_type":"article","og_title":"Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations","og_description":"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.","og_url":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/","og_site_name":"WebHi Tutorials &amp; Documentations","article_publisher":"https:\/\/www.facebook.com\/webhi.technology","article_published_time":"2024-09-04T16:02:45+00:00","article_modified_time":"2024-09-04T16:02:47+00:00","og_image":[{"url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2024\/09\/haproxy_loadbalance_en.jpg"}],"author":"webhi","twitter_card":"summary_large_image","twitter_creator":"@WebHiTechnology","twitter_site":"@WebHiTechnology","twitter_misc":{"Written by":"webhi","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#article","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/"},"author":{"name":"webhi","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54"},"headline":"Load Balancing with HAProxy on Ubuntu","datePublished":"2024-09-04T16:02:45+00:00","dateModified":"2024-09-04T16:02:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/"},"wordCount":1304,"commentCount":0,"publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"articleSection":["Virtualization &amp; Cloud computing","Web servers"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/","url":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/","name":"Load Balancing with HAProxy on Ubuntu - WebHi Tutorials &amp; Documentations","isPartOf":{"@id":"https:\/\/www.webhi.com\/how-to\/#website"},"datePublished":"2024-09-04T16:02:45+00:00","dateModified":"2024-09-04T16:02:47+00:00","description":"Learn how to set up and configure HAProxy on Ubuntu for efficient load balancing. This guide covers installation, configuration, and optimization techniques.","breadcrumb":{"@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.webhi.com\/how-to\/load-balancing-haproxy-ubuntu-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webhi.com\/how-to\/"},{"@type":"ListItem","position":2,"name":"Load Balancing with HAProxy on Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/www.webhi.com\/how-to\/#website","url":"https:\/\/www.webhi.com\/how-to\/","name":"WebHi Tutorials &amp; Documentations","description":"System administration and knowledge base","publisher":{"@id":"https:\/\/www.webhi.com\/how-to\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webhi.com\/how-to\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webhi.com\/how-to\/#organization","name":"WebHi Technology","url":"https:\/\/www.webhi.com\/how-to\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/","url":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","contentUrl":"https:\/\/www.webhi.com\/how-to\/gilrogre\/2022\/07\/logo.png","width":288,"height":95,"caption":"WebHi Technology"},"image":{"@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webhi.technology","https:\/\/twitter.com\/WebHiTechnology"]},{"@type":"Person","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/b31e76e2311cdc0bb90f5e2733059a54","name":"webhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webhi.com\/how-to\/#\/schema\/person\/image\/","url":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435","contentUrl":"https:\/\/www.webhi.com\/how-to\/ahuphiph\/litespeed\/avatar\/e20da107d0f4c765ead2eef88ad019d8.jpg?ver=1783634435","caption":"webhi"},"sameAs":["https:\/\/www.webhi.com\/how-to"],"url":"https:\/\/www.webhi.com\/how-to\/author\/webhi\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/9212"}],"collection":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/comments?post=9212"}],"version-history":[{"count":5,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/9212\/revisions"}],"predecessor-version":[{"id":9232,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/posts\/9212\/revisions\/9232"}],"wp:attachment":[{"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/media?parent=9212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/categories?post=9212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webhi.com\/how-to\/wp-json\/wp\/v2\/tags?post=9212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}