【问题标题】:nginx-proxy doesn't work with swagger-ui docker container 502 Bad Gatewaynginx-proxy 不适用于 swagger-ui docker container 502 Bad Gateway
【发布时间】:2018-10-11 04:18:54
【问题描述】:

我想将我的本地 url 从 'localhost:port' 更改为项目相关的 url。堆栈中的每个其他容器(节点服务器等)都可以工作,但只有 swagger 容器会给出错误 502 Bad Gateway。

我将此添加到我的 /etc/hosts 文件中:

 127.0.0.1       my-api-doc.local

这是我的 docker-compose.yml 文件:

   version: '3'
   services: 
     api_doc:
       image: swaggerapi/swagger-ui
       environment:
         - "VIRTUAL_HOST=my-api-doc.local"
         - "VIRTUAL_PORT=4000"
       ports:
         - "4000:8080"
       links:
         - nginx-proxy


     nginx-proxy:
       image: jwilder/nginx-proxy:alpine
       ports:
         - "80:80"
         - "443:443"
       volumes:
         - /var/run/docker.sock:/tmp/docker.sock:ro
       restart: unless-stopped

问题是,当我在浏览器中转到“my-api-doc.local”时,收到“502 Bad Gateway”错误。当我尝试 'localhost:4000' 时,它可以工作。

【问题讨论】:

    标签: nginx docker-compose swagger swagger-ui jwilder-nginx-proxy


    【解决方案1】:

    我将 nginx 管理器更改为 'traefik' docker 映像。这对我来说是固定的问题。我最终的 docker compose 文件如下:

    version: '3'
    services:
      apiDoc:
        image: swaggerapi/swagger-ui
        container_name: "linkit_api_doc"
        volumes:
        - ../../src/server/:/usr/app/
        depends_on:
          - server
        labels:
        - "traefik.frontend.rule=Host:linkit-air-api.local"
        - "traefik.port=8080"
    
      reverse-proxy:
        image: traefik  # The official Traefik docker image
        command: --api --docker  # Enables the web UI and tells Træfik to listen to docker
        ports:
          - "80:80"      # The HTTP port
          - "8080:8080"  # The Web UI (enabled by --api)
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock  # So that Traefik can listen to the Docker events
    

    【讨论】:

      猜你喜欢
      • 2019-06-14
      • 2016-10-23
      • 2022-12-14
      • 2020-08-01
      • 2017-04-18
      • 2022-01-24
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多