---
title: "Discussion on \"Understanding nginx: Web Server, Reverse Proxy, and Load Balancer Explained with Docker Compose\" | Hashnode"
description: "Discussion on \"Understanding nginx: Web Server, Reverse Proxy, and Load Balancer Explained with Docker Compose\". Learn to build a contact form app with nginx load balancer and proxy through Docker Compose"
url: "https://hashnode.com/posts/understanding-nginx-web-server-reverse-proxy-and-load-balancer-explained-with-docker-compose/689396d888fd0a3a5d2544be"
---

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

Discussion

# [Understanding nginx: Web Server, Reverse Proxy, and Load Balancer Explained with Docker Compose](https://blog.sachindu.me/understanding-nginx-web-server-reverse-proxy-and-load-balancer-explained-with-docker-compose?utm_source=hashnode&utm_medium=feed)

Learn to build a contact form app with nginx load balancer and proxy through Docker Compose

Aug 6, 2025 · 8 min read · blog.sachindu.me  
Updated Nov 21  
Read the article

-   [#nginx](https://hashnode.com/tag/nginx)
-   [#docker](https://hashnode.com/tag/docker)
-   [#docker-compose](https://hashnode.com/tag/docker-compose)
-   [#load-balancing](https://hashnode.com/tag/load-balancing)
-   [#reverse-proxy](https://hashnode.com/tag/reverse-proxy)
-   [#webserver](https://hashnode.com/tag/webserver)
-   [#apache](https://hashnode.com/tag/apache)
-   [#http](https://hashnode.com/tag/http)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#devops](https://hashnode.com/tag/devops)
-   [#devops-articles](https://hashnode.com/tag/devops-articles)

## Written by

[Sachindu Malshan](https://hashnode.com/@sachindumalshan)

@sachindumalshan

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

Turn problems into solutions

DevOps Enthusiast

## Responses 1

Markdown supported · ⌘↵ to post

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

[Nov 4](https://hashnode.com/posts/understanding-nginx-web-server-reverse-proxy-and-load-balancer-explained-with-docker-compose/689396d888fd0a3a5d2544be/comment/6aebb9343681c89d6c69b042)

Clear framing of nginx as static server, reverse proxy, and load balancer in one compose stack. The ops habit that saves the most 502 tickets is resolving upstreams by compose service name on the shared network, not by published host ports — leave app ports internal and expose only 80/443 on the proxy service. After a backend recreate, a long-lived nginx worker can keep a stale resolved address unless you reload/recreate the proxy or use a variable-plus-resolver pattern, so treat upstream DNS churn as part of the deploy, not an afterthought.

For the load-balancer side I prefer least\_conn once replicas are equal, keep max\_fails and fail\_timeout modest so a crashed container leaves the pool quickly, and enable upstream keepalive with protocol 1.1 plus an empty Connection header so sockets actually reuse. Always pass Host, X-Forwarded-For, and X-Forwarded-Proto so apps build public redirects correctly. After compose scale I hit each upstream by service name, then through nginx, and compare Set-Cookie and latency — mismatches almost always mean a stale upstream block or a missing forwarded header, not the balancing algorithm itself.
