Docker compose NGINX反向代理不适用于其他docker容器
我在docker compose中设置了两个docker容器。现在我想使用nginx的proxy_pass特性来代理从nginx到其他容器的连接 docker composeDocker compose NGINX反向代理不适用于其他docker容器,docker-compose,reverse-proxy,Docker Compose,Reverse Proxy,我在docker compose中设置了两个docker容器。现在我想使用nginx的proxy_pass特性来代理从nginx到其他容器的连接 docker compose version: '3.4' services: reverse_proxy: image: nginx:alpine volumes: - ./nginx.conf:/etc/nginx/nginx.conf - ./error.log:/var/log/nginx/erro
version: '3.4'
services:
reverse_proxy:
image: nginx:alpine
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./error.log:/var/log/nginx/error.log
ports:
- "8081:8081"
apigateway.api:
image: ${REGISTRY:-configurator}/apigateway.api:${TAG:-latest}
build:
context: .
dockerfile: src/Services/ApiGateway/ApiGateway.Api/Dockerfile
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
ports:
- "58732:80"
nginx形态
worker_processes 1;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
client_max_body_size 16M;
# MIME
include mime.types;
default_type application/octet-stream;
upstream apigateway {
server apigateway.api:58732;
}
server {
listen 8081;
# reverse proxy
location /configurator-api-gw/ {
proxy_pass http://apigateway/;
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;
}
}
}
当我现在访问时,我在error.log中发现以下错误。我也尝试过不同的方法和其他一些例子,但我不明白为什么这不起作用
2019/03/08 06:30:29[错误]77:*6连接失败111:连接失败
连接到上游时被拒绝,客户端:172.28.0.1,服务器:,
请求:GET/configurator api gw/swagger HTTP/1.1,上游:
,主机:localhost:8081
我已经解决了这个问题。问题在于服务器apigateway.api:58732;这里需要将端口80用作docker网络内部的端口。谢谢!。其他人的问题是因为他们使用localhost或127.0.0.1之类的东西,所以很难找到这个问题。