首页 > 解决方案 > Traefik 2.2 网关超时问题

问题描述

我一直在尝试使用基本官方指南设置 traefik v2.2。我有一个 Spring Boot 服务,我已经将它容器化并且工作正常。

这是我的 spring boot 服务的 docker compose:

version: "3"

services:
  spring-boot-traefik-app:
    image: spring-boot-traefik-example:latest
    labels:
      - "traefik.http.routers.spring-boot-traefik-app.rule=Host(`springboot.traefik.app`)"

这是我的 Traefik docker compose :

version: "3"

services:
  reverse-proxy:
    # The official v2 Traefik docker image
    image: traefik:v2.2
    # Enables the web UI and tells Traefik to listen to docker
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
    ports:
      # The HTTP port
      - "80:80"
      # The Web UI (enabled by --api.insecure=true)
      - "8080:8080"
    volumes:
      # So that Traefik can listen to the Docker events
      - /var/run/docker.sock:/var/run/docker.sock

现在,我正在尝试通过以下方式执行 curl 请求:

curl -H Host:springboot.traefik.app http://127.0.0.1

因为我只是在上下文路径“/”上返回服务信息,所以它应该返回了一些东西。服务独立工作正常。但是当我尝试在代理后面运行时,它会给我网关超时错误。我不确定 traefik 是否正常工作。我错过了什么吗?官方指南使用 whoami 图像,这是我试图用 Spring boot 创建的。此外,traefik 仪表板可以正确显示详细信息。

标签: spring-bootdockerdocker-composetraefik

解决方案


也许您应该为您的 traefik 配置定义一个入口点。您可能没有 traefik.toml 文件(我更喜欢个人使用)。无论如何,您应该--entryPoints.web.address=:80为您的 traefik 容器添加命令,并将标签添加到traefik.http.routers.spring-boot-traefik-app.entrypoints=web您的 springboot 容器中。我希望它有效!


推荐阅读