Putting nginx in front and dropping published app ports is the right security move — the piece that usually bites next is upstream health versus in-memory Flask sessions. Round-robin across replicas without a shared store (Redis or similar) looks like random logouts; either keep session state outside the workers or pin stickiness only where you must and document why.
On the proxy side I enable upstream keepalive with protocol 1.1 and an empty Connection header so sockets to the Flask containers actually reuse, and I keep max_fails plus fail_timeout modest so a crashed replica drops out quickly. After compose scale, hit each upstream by service name on the compose network, then through nginx, and compare Set-Cookie and latency — mismatches almost always mean a stale upstream block or a missing Host / X-Forwarded-Proto header, not the load-balancing algorithm itself.
CDN Edge Ops
Putting nginx in front and dropping published app ports is the right security move — the piece that usually bites next is upstream health versus in-memory Flask sessions. Round-robin across replicas without a shared store (Redis or similar) looks like random logouts; either keep session state outside the workers or pin stickiness only where you must and document why.
On the proxy side I enable upstream keepalive with protocol 1.1 and an empty Connection header so sockets to the Flask containers actually reuse, and I keep max_fails plus fail_timeout modest so a crashed replica drops out quickly. After compose scale, hit each upstream by service name on the compose network, then through nginx, and compare Set-Cookie and latency — mismatches almost always mean a stale upstream block or a missing Host / X-Forwarded-Proto header, not the load-balancing algorithm itself.