【问题标题】:DNS in docker-compose, map to non-80 port?docker-compose中的DNS,映射到非80端口?
【发布时间】:2018-06-04 12:59:38
【问题描述】:

在尝试使用 docker-compose 时,我遇到了 NGINX 和 dns 的一些问题。错误是 NGINX 中的常规“连接到上游时连接被拒绝”。我认为问题是由于端口号引起的。

this one 等在线示例在端口 80 上运行 NGINX,这不会导致问题。

docker-compose.yml:

version: '3'
services:
  http-server:
    networks:
      - mynetwork
    image: nginx_image
    ports:
      - 8080:8080
    depends_on:
      - frontend
      - rest_api
  frontend:
    networks:
      - mynetwork
    image: frontend_image
    ports:
      - 8001:8001
  rest_api:
    networks:
      - mynetwork
    image: rest_api_image
    ports:
      - 8000:8000

网络: 我的网络: 司机:桥

nginx_image 的 nginx.conf 有这个块:

server {
    listen 8080;

location /static/js/  {
  proxy_pass http://frontend;
    }

location /static/css/  {
    proxy_pass http://frontend;
    }

location /static/ {
    proxy_pass http://rest_api;
}

location / {
proxy_pass http://frontend;
    }

location /rest_api/ {
    proxy_pass http://rest_api;
    }
}

现在,前端和api都通过80端口调用,而应该是8001和8000。

我错过了什么?我希望 docker-compose 能够自动进行端口映射。

提前致谢!

亲切的问候,

DA

EDIT1:这是错误(包括主机名建议)

EDIT2:更新问题

http-server_1  | 2018/06/04 14:47:50 [error] 14#14: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: , request: "GET /rest_api/admin/ HTTP/1.1", upstream: "http://172.18.0.2:80/rest_api/admin/", host: "localhost:8080"

【问题讨论】:

    标签: docker nginx docker-compose


    【解决方案1】:

    您必须指定主机名:

      frontend:
        image: frontend_image
        hostname: frontend
        ports:
          - 8001:8001
      rest_api:
        hostname: rest_api
    

    【讨论】:

    • 有道理,虽然错误仍然存​​在,你认为这是别的什么吗?我在问题中添加了错误。
    • nginx 尝试连接到端口 80。但是您的应用程序侦听 8001 您应该为 nginx 配置指定端口:proxy_pass frontend:8001; proxy_pass rest_api:8000;
    猜你喜欢
    • 2022-10-17
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多