---
title: "Discussion on \"Load Balancing with Nginx and Docker\" | Hashnode"
description: "Discussion on \"Load Balancing with Nginx and Docker\". Load Balancing a Golang API with Nginx and Docker"
url: "https://hashnode.com/posts/load-balancing-with-nginx-and-docker/6319af1b6b34d71380dad730"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Load Balancing with Nginx and Docker](https://izypro.hashnode.dev/load-balancing-with-nginx-and-docker?utm_source=hashnode&utm_medium=feed)

Load Balancing a Golang API with Nginx and Docker

Sep 8, 2022 · 5 min read · izypro.hashnode.dev  
Read the article

-   [#load-balancing](https://hashnode.com/tag/load-balancing)
-   [#docker](https://hashnode.com/tag/docker)
-   [#apis](https://hashnode.com/tag/apis)
-   [#nginx](https://hashnode.com/tag/nginx)
-   [#docker-compose](https://hashnode.com/tag/docker-compose)

## Written by

[Israel Ulelu](https://hashnode.com/@IzyPro)

@IzyPro

  
[View profile](https://hashnode.com/@IzyPro)

Software Engineer

Solving problems with software

## Responses 1

Markdown supported · ⌘↵ to post

[CDN Edge Ops](https://hashnode.com/@cdnedgeops)

[Nov 5](https://hashnode.com/posts/load-balancing-with-nginx-and-docker/6319af1b6b34d71380dad730/comment/6aebd3a736531064cf3816de)

Nginx as a Docker-side load balancer stays reliable when the proxy and every backend share one user-defined network and the upstream list uses service DNS, not host-published ports. Publish only 80/443 on the nginx service; leave app ports internal so a stray host bind cannot bypass the balancer. Prefer least\_conn once replicas are roughly equal, and set modest max\_fails/fail\_timeout so a crashed container leaves the pool instead of turning every other request into a 502.

Static upstream members are resolved when the worker loads config — after a recreate or compose scale the new IPs stay invisible until nginx reloads or you use a resolver-aware variable upstream. Make that reload part of the scale checklist. Pin proxy\_http\_version 1.1, clear Connection for keepalive, and forward Host plus X-Forwarded-For/Proto so apps build redirects against the public scheme. After any scale I hit each replica by service name from inside the nginx container, then the same path through the public vhost, and compare status and latency — mismatches almost always mean a stale upstream list or a trailing-slash join, not the image tag.
