docker- nginx-反向代理:使用docker-compose进行构建时,上游未找到主机
我正在使用NGINX容器将某些请求重定向到另一个容器.在运行docker-compose up -d时,出现了以下错误.
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:在/etc/nginx/nginx.conf:10的上游"abcplus-visualize:61613"中找不到主机nginx:[emerg]主机未在/etc/nginx/nginx.conf:10 "的上游"abcplus-visualize:61613"中找到
" 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"
下面是我的docker-compose.yml文件
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
下面是我的nginx.conf文件
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;
}
}
}
我们在上游提供的服务器名称存在问题.我尝试使用 abcplus-visualize 而不是 abcplus-visualize ,它可以正常工作.可能是在使用hypen(-")启动docker-compose服务器名称时,它并没有低估.
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.