Nginx routing setup within Docker container, request timing out with 502
You will notice in this upstream block:

upstream api {
    server server:5000;
}


I called it api but then I say server server:5000;. That was the problem because I originally had it as:

upstream server {
    server server:5000;
}


but then thought that server might be a reserved operator in the Nginx world so I changed it to api but did not change it inside the block.

So it should have been:

upstream api {
    server api:5000;
}


After changing it, the xhr pending and timing out 502 errors went away.