daniil/full-stack-js-docker-tutorial

The nginx Service fails to find the client:300 in this Example code

Closed this issue · 7 comments

Hi, thanks for the great example code, but I am strugling to get a similar example working. I then reverted to your own code and I am getting the same issue/error:

nginx: [emerg] host not found in upstream "client:3000" in /etc/nginx/conf.d/default.conf:2

Could you help me in understanding what the issue is please?

Hey, glad it could be helpful to you!

I am assuming your nginx/default.conf looks something like:

upstream ui {
  server client:3000;
}

In the code I have it's ui:3000, which afaik should be the name of your Docker service for front-end/client in the docker-compose.yaml, so in my code it's be line 51.

So just try checking that it's all mapped correctly using the same values, that's be my best guess 🤔

It is odd, I have that. Okay, so one thing that seemed to be causing it was setting the container_name: in the docker-compose.yml. Did you manage to get this working locally? Now, when I attempt to connect to the localhost:4000 (the nginx service), I get Invalid Host header shown in the browser. I really appreciate the quick response. Thank you again...

Hey again, I am not sure exactly what might be causing that to be honest, however I tried pulling the repo again and try to build and start it from scratch and I ran into an issue where both server and ui services were missing their node_modules folders, so maybe that was causing issues for you as well.

I have pushed a fix now that made things working again for me, maybe that'll fix the issue you're having?

It is not that. Does this all work for you locally, so you can hit nginx at localhost:8008 and it redirects to the client and then to the server correctly? I am not getting "Cannot GET /<some_id>"... I am very confused. I assume that this should be demonstratable at localhost?

Yes, sorry if that wasn't clear. I have tried running the cloned repo locally and am able to access it via nginx (8008) as well as separate ui and server services under their own ports. As I mentioned though I had an issue with node_modules that I had to patch.

But yes, it all works on localhost for me after clean clone.

What happens when you try accessing services by their own port? What about running ui and server services directly, without compose, by just building and upping them from their own folder?

I would look there trying to identify what the issue might be, is it one of the services or the nginx pulling it together or docker-compose messing up.

Also looking up the error you mentioned gave me a couple of threads about needing to do something in your webpack or whichever live server config you are using.

I know compose logs are not the most readable, but anything jumping out at you when the services are trying to come up?

Hi, thank you, I have it working as expected. Thank you very much for your time with this - it was most appreciated.

Happy to help and to hear you got it working! Out of curiosity, what was it in the end?