Description: There is an nginx Docker container that listens on port 80, the purpose of which is to redirect the traffic to two other containers statichtml1 and statichtml2 but this redirection is not working.
Fix the problem.
IMPORTANT. You can restart all containers, but don’t stop or remove them.
Root (sudo) Access:Â True
Test:Â The nginx container must redirect the traffic to the statichtml1 and statichtml2 containers:
curl http://localhost returns the Welcome to nginx default page
curl http://localhost/1Â returns HelloWorld;1
curl http://localhost/2Â returns HelloWorld;2
The “Check My Solution” button runs the script /home/admin/agent/check.sh, which you can see and execute.
Time to Solve:Â 15 minutes.
First of all, we need to know what we’re working with. Let’s explore the errors and the docker containers running:
curl -v http://localhost/1* Host localhost:80 was resolved.* IPv6: ::1* IPv4: 127.0.0.1* Trying [::1]:80...* Connected to localhost (::1) port 80* using HTTP/1.x> GET /1 HTTP/1.1> Host: localhost> User-Agent: curl/8.14.1> Accept: */*>* Request completely sent off< HTTP/1.1 504 Gateway Time-out< Server: nginx/1.29.3< Date: Sun, 07 Dec 2025 23:24:22 GMT< Content-Type: text/html< Content-Length: 167< Connection: keep-alive<<html><head><title>504Gateway Time-out</title></head><body><center><h1>504Gateway Time-out</h1></center><hr><center>nginx/1.29.3</center></body></html>* Connection #0 to host localhost left intact
docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES89bf0e394bb9 statichtml:2 "busybox httpd -f -v…" 6 days ago Up 20 seconds 3000/tcp statichtml21f96c1876662 statichtml:1 "busybox httpd -f -v…" 6 days ago Up 20 seconds 3000/tcp statichtml17440094fc321 nginx "/docker-entrypoint.…" 6 days ago Up 20 seconds 0.0.0.0:80->80/tcp, [::]:80->80/tcp nginxdocker network lsNETWORK ID NAME DRIVER SCOPE9d257323d6f9 bridge bridge locala7250a90f896 host host localb08d312e9d16 none null localcc3e04c023f1 static-net bridge local
Oh, we have more than one network. Interesting. Let’s look into it:
First issue is here! nginx container is not on the same network than the destination containers. Basic routing issue.
If nginx is a proxy to the other containers, it needs to be on the same network. Otherwise, no traffic will be able to reach the destination containers.
Let’s connect the nginx proxy to the static-net network:
At first I thought that was it. But the challenge wasn’t done yet. curl http://localhost/1 was now returning a 502 - Bad Gateway.
We have something else that we need to fix. Let’s look at the nginx config. It’s on the host at app/default.conf. It’s been mounted in the nginx container:
Did you notice it? The statichtml containers are exposing the port 3000, but this config is using the default HTTP port (80). We have a second issue to fix here!
We need to specify the port 3000 for the proxy redirection to work: