2

OVERVIEW

Nginx runs in Docker container, also NodeJS application (worker) runs in another one, all managed by Docker Compose. Configuration has an upstream: container of worker 1 is also up and running, while node with worker 2 is not.

upstream nodeapp {
    server appconfig_host-nodejs-app-worker_1:3000;
    server appconfig_host-nodejs-app-worker_2:3000;
}

It is then used in location block to proxy pass all requests.

location /api/ {
  proxy_pass http://nodeapp/;
}

ACTUAL RESULT

When worker 2 is in configuration (the container which is not running), I got error [emerg] 1#1: host not found in upstream "appconfig_host-nodejs-app-worker_2:3000" and container exits with code 1.

When I remove line with second worker from upstream configuration, and keep just worker 1, then everything works just fine, proxy works as expected, serving my NodeJS app at /localhost/api/.

EXPECTED RESULT

I'd expect Nginx built-in balancing working so that it holds sending requests to worker 2, until it is alive again. I.e. service operates normally, not having worker 2 in the upstream, so all requests go to worker 1.

Please advise what might be wrong here, as I could not find any way to fix that for few hours already. Thanks a lot in advance.

2 Answers2

2

Problem is that nginx tries to resolve any DNS names you define in the configuration at startup time (rather than request time) and it fails if it cannot resolve one of the names.

Check this answer for possible solutions/workarounds: https://stackoverflow.com/a/32846603/1078969

whites11
  • 12,008
  • 3
  • 36
  • 53
1

"Nginx container exits with code 1".

This error can also be caused by a syntax error in a .conf file, such as inserting a colon between name:value pairs when you shouldnt, due to confounding syntax rules with different config files.

You stand a good chance of finding a complaint that points you to the line in question in the log files.

pbgswd
  • 19
  • 3
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 21 '22 at 21:22