Docker Nginx stopped: [emerg] 1#1: host not found in upstream

6.5K    Asked by FerminaZamorano in Data Science , Asked on Jul 15, 2021

Hi there, So i've been using nginx with docker in the AWS ECS service.

But recently i got an error or more like my nginx sevice just stopped working, i suspect it's because the proxy_path has become unreachabel for one of the servers

This is the error i am receiving:

[emerg] 1#1: host not found in upstream "dev-example.io" in /etc/nginx/conf.d/default.conf:988
And this is what my config file looks like:
server {
       listen      80;
       server_name     test.com;
       location / {
          proxy_pass   
          proxy_redirect     off;
          ##proxy_set_header   Host             $host;
          proxy_set_header   X-Real-IP        $remote_addr;
          proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
          client_max_body_size       10m;
          client_body_buffer_size    128k;
          proxy_connect_timeout      90;
          proxy_send_timeout         90;
          proxy_read_timeout         90;
          proxy_buffer_size          4k;
          proxy_buffers              4 32k;
          proxy_busy_buffers_size    64k;
          proxy_temp_file_write_size 64k;
       }
}
server {
   listen       80 default_server;
   server_name  localhost;
   #charset koi8-r;
   #access_log  /var/log/nginx/log/host.access.log  main;
   location / {
      root   /usr/share/nginx/html;
      index  index.html index.htm;
   }
   #error_page  404              /404.html;
   # redirect server error pages to the static page /50x.html
   #
   error_page   500 502 503 504  /50x.html;
   location = /50x.html {
      root   /usr/share/nginx/html;
   }
}

So i have a lot of servers in this, even if one goes down i don't mind, I just need my nginx to keep running. Any suggestion on how to fix it?


Answered by Hasegawa Saito

To resolve host not found in upstream you can include a resolver directive in your config to prevent any more crashes , like this :

server {
       listen 80;
       server_name test.com;
       location / {
          resolver 8.8.8.8
          proxy_pass
          proxy_redirect off;

 ...

But be careful using a public DNS is dangerous, as the DNS requests can be easily spoofed. You can work around this by using a secure DNS server.

Hope that helped :smile:



Your Answer

Interviews

Parent Categories