---
title: "Comment by Node Edge Ops on \"Containerising a Three-Tier MERN E-Commerce App with Docker and Nginx\" | Hashnode"
description: "For a Compose MERN stack the durable pattern is nginx as the only public listener, with the Node API and Mongo on an internal network only. Resolve upstreams by"
url: "https://hashnode.com/posts/containerising-a-three-tier-mern-e-commerce-app-with-docker-and-nginx/68ebaf13c91d0ed3c5f49631/comment/6aebcf7771b60f911e3d3298"
---

[Discussion](https://hashnode.com/posts/containerising-a-three-tier-mern-e-commerce-app-with-docker-and-nginx/68ebaf13c91d0ed3c5f49631)

Comment [Containerising a Three-Tier MERN E-Commerce App with Docker and Nginx](https://hashnode.com/posts/containerising-a-three-tier-mern-e-commerce-app-with-docker-and-nginx/68ebaf13c91d0ed3c5f49631)

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 5](https://hashnode.com/posts/containerising-a-three-tier-mern-e-commerce-app-with-docker-and-nginx/68ebaf13c91d0ed3c5f49631/comment/6aebcf7771b60f911e3d3298)

For a Compose MERN stack the durable pattern is nginx as the only public listener, with the Node API and Mongo on an internal network only. Resolve upstreams by Compose service name, not published host ports — publishing the API or DB on the host can bypass ufw and widen the attack surface. Keep proxy\_http\_version 1.1 with Connection cleared for keepalive into Node, and forward Host plus X-Forwarded-For / X-Forwarded-Proto so the app sees the public scheme for absolute URLs and cookies.

Path joining still bites after containers come up: a trailing-slash mismatch between location and proxy\_pass doubles or strips a prefix, so the SPA gets HTML for an API call or Node 404s a route it owns. After compose up I curl the API service name from the nginx container first, then the same path through published 80/443, and compare status timing. Stale resolved IPs after a recreate need a variable-plus-resolver pattern or a proxy recreate on deploy — most post-redeploy 502s are upstream DNS or path joining, not the Node image. Leave Mongo unpublished.
