Nginx docker stopped: [quit] 1 # 1: host not found in upstream

I am running docker-nginx on an ECS server. My nginx service stops abruptly because the proxy_path of one of the servers is unavailable. The error is as follows:

[emerg] 1#1: host not found in upstream "dev-example.io" in /etc/nginx/conf.d/default.conf:988 

My configuration file looks like this:

  server { listen 80; server_name test.com; location / { proxy_pass http://dev-exapmle.io:5016/; 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; } } 

I have many servers in the configuration file, even if one server does not work, I need to run nginx. Is there any way to fix this?

Any suggestion to fix this problem would be appreciated.

+9
source share
3 answers

Enable to prevent Nginx from crashing if your site is down, enable the resolver directive as shown below:

  server { listen 80; server_name test.com; location / { resolver 8.8.8.8 proxy_pass http://dev-exapmle.io:5016/; proxy_redirect off; ... 

ATTENTION! Using public DNS poses a security risk to your server, as your DNS queries may be tampered with. If this is a problem, you must point the resolver to a secure DNS server.

+5
source

This usually means that the DNS name provided by you as the upstream server cannot be resolved. To test it, go to the nginx server and try to run the upstream ping server and check if the name resolution is resolved correctly. If its docker container tries docker exec -it to get a shell, try pinging up to check for name resolution. If the contianer is stopped, try using the IP address instead of the DNS name in the server block.

 proxy_pass http://<IP ADDRESS>:5016/; 

You can also use the resolver directive if you want to use a different DNS server for this location than the host system:

 resolver 8.8.8.8; 
+3
source

Just adding a recognizer did not solve the problem in my case. But I was able to get around this using a host variable. Also, I think it makes more sense to use Docker DNS on 127.0.0.11 (this is a fixed IP address).

Example:

 server { listen 80; server_name test.com; location / { resolver 127.0.0.11; set example dev-example.io:5016 proxy_pass http://$example; } } 

I found a variable solution on this page .

+2
source

Source: https://habr.com/ru/post/1015656/


All Articles