Docker- nginx -Reverse proxy : host not found in upstream when building with docker-compose

徘徊边缘 提交于 2021-02-09 06:58:19

问题


I am using NGINX container to redirect certain requests to another container.While running docker-compose up -d , i am getting bellow error.

" 2019/09/26 18:05:00 [emerg] 1#1: host not found in upstream "abcplus-visualize:61613" in /etc/nginx/nginx.conf:10 nginx: [emerg] host not found in upstream "abcplus-visualize:61613" in /etc/nginx/nginx.conf:10"

below is my docker-compose.yml file

version: '2'

services:
    reverseproxy:
        image: reverseproxy
        ports:
            - 49665:2181
        restart: always

    abcplus-visualize:
        depends_on:
            - reverseproxy
        image: abcplus-visualize:latest
        restart: always

below is my nginx.conf file

worker_processes 1;

events { worker_connections 1024; }

http {

    sendfile on;

    upstream docker-abcplus {
        server abcplus-visualize:61613;
    }

    server {
        listen 2181;
        server_name localhost;

          location / {
            proxy_pass         http://docker-abcplus;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
        }
    }
}

回答1:


try to use :

upstream docker-abcplus {
    server abcplus-visualize:61613 max_fails=6 fail_timeout=30s;
}

I think your upstream fails too fast before the app is running




回答2:


There was issue with Server name which we are giving in upstream. I tried with abcplus-visualize instead of abcplus-visualize , its working fine. May be while starting docker-compose server name with hypen("-") it is not understating.



来源:https://stackoverflow.com/questions/58122870/docker-nginx-reverse-proxy-host-not-found-in-upstream-when-building-with-doc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!