{"id":2333,"date":"2026-07-24T00:26:26","date_gmt":"2026-07-23T17:26:26","guid":{"rendered":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-set-up-a-load-balancer-a-step-by-step-guide\/"},"modified":"2026-07-24T00:26:26","modified_gmt":"2026-07-23T17:26:26","slug":"how-to-set-up-a-load-balancer-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/sumberlaba.com\/index.php\/2026\/07\/24\/how-to-set-up-a-load-balancer-a-step-by-step-guide\/","title":{"rendered":"How to Set Up a Load Balancer: A Step-by-Step Guide"},"content":{"rendered":"<h1>How to Set Up a Load Balancer: A Step-by-Step Guide<\/h1>\n<p>Load balancing distributes incoming traffic across multiple servers to improve performance, reliability, and scalability. Whether using hardware or software like NGINX or HAProxy, a proper setup ensures your application stays available under heavy load. This guide walks through the essential steps for configuring a basic load balancer using NGINX as an example.<\/p>\n<p>Before you begin, you need at least two backend servers running the same application (e.g., web servers on ports 3000 and 3001) and one load balancer server. All servers should have a static IP address and be on the same network. For this tutorial, we assume Ubuntu 22.04 with NGINX installed.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/via.placeholder.com\/800x600\/4a90d9\/ffffff?text=how%20to%20set%20up%20a%20load%20balancer\" alt=\"Article illustration\" style=\"display:block;margin:20px auto;max-width:100%;height:auto;border-radius:8px;\" \/><\/p>\n<h2>1. Install and Configure NGINX as a Load Balancer<\/h2>\n<p>On the load balancer machine, install NGINX:<\/p>\n<ul>\n<li><code>sudo apt update && sudo apt install nginx -y<\/code><\/li>\n<li>Open the default config: <code>sudo nano \/etc\/nginx\/sites-available\/default<\/code><\/li>\n<li>Replace the contents with a basic upstream block pointing to your backend servers.<\/li>\n<\/ul>\n<h3>Example Upstream Configuration<\/h3>\n<p>Inside the <code>http<\/code> block, add:<\/p>\n<pre>upstream backend {\n    server 192.168.1.10:3000;\n    server 192.168.1.11:3001;\n}<\/pre>\n<p>Then in the <code>server<\/code> block, proxy requests to the upstream group:<\/p>\n<pre>location \/ {\n    proxy_pass http:\/\/backend;\n}<\/pre>\n<h2>2. Choose a Load Balancing Method<\/h2>\n<p>NGINX supports several algorithms. By default, it uses round-robin. To switch, add a directive inside the upstream block:<\/p>\n<ul>\n<li><strong>Least Connections:<\/strong> <code>least_conn;<\/code> \u2013 sends traffic to the server with fewest active connections.<\/li>\n<li><strong>IP Hash:<\/strong> <code>ip_hash;<\/code> \u2013 ensures a client always reaches the same backend (useful for sessions).<\/li>\n<li><strong>Weighted:<\/strong> Add <code>weight=3<\/code> after a server IP to give it more traffic.<\/li>\n<\/ul>\n<h2>3. Enable Health Checks (Optional but Recommended)<\/h2>\n<p>NGINX Plus has built-in health checks; for open source, you can rely on proxy_next_upstream to retry failed requests. Add inside the <code>location<\/code> block:<\/p>\n<pre>proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;<\/pre>\n<p>Alternatively, use a third-party module like nginx_upstream_check_module.<\/p>\n<h2>4. Test and Start the Load Balancer<\/h2>\n<p>Check the configuration for syntax errors:<\/p>\n<pre>sudo nginx -t<\/pre>\n<p>If successful, restart NGINX:<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<p>Now access the load balancer&#8217;s IP address in a browser. Traffic should be distributed across your backend servers.<\/p>\n<h2>Conclusion<\/h2>\n<p>Setting up a load balancer with NGINX is straightforward and provides immediate benefits in reliability and performance. Start with a simple round-robin, then add health checks and session persistence as your application grows. Monitor your server logs to verify traffic distribution and adjust weights or algorithms as needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Set Up a Load Balancer: A Step-by-Step Guide Load balancing distributes incoming traffic across multiple servers to improve performance, reliability, and scalability. Whether using hardware or software like NGINX or HAProxy, a proper setup ensures your application stays available under heavy load. This guide walks through the essential steps for configuring a basic &hellip; <\/p>\n","protected":false},"author":2716,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2333","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/users\/2716"}],"replies":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/comments?post=2333"}],"version-history":[{"count":0,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2333\/revisions"}],"wp:attachment":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media?parent=2333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/categories?post=2333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/tags?post=2333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}