nginx代理不适用于swagger-ui docker容器502 Bad Gateway

时间:2018-10-01 18:56:49

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

我想将本地URL从“ localhost:port”更改为与项目相关的URL。堆栈中的所有其他容器(节点服务器等)都可以工作,但是只有摇摇欲坠的容器才会给出错误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”时,它可以工作。

1 个答案:

答案 0 :(得分:0)

我将nginx管理器更改为“ traefik”泊坞窗映像。这对我来说是固定的问题。我最后的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