Traefik 3 在 mailpit 8025 端口上返回“404 页面未找到” - 无法反向代理到特定容器端口

问题描述 投票:0回答:1

问题相当普遍,但我有一个 mailpit 的示例:我无法反向代理到使用特定端口的 docker 容器应用程序。

我正在使用 Traefik 并设置了这些文件:

Traefik/docker-compose.yaml

services:

  traefik:
    image: traefik:latest
    container_name: traefik
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./htpasswd:/htpasswd
      - ./traefik.yaml:/etc/traefik/traefik.yaml
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.http.routers.dashboard.rule=Host(`localhost`) && (PathPrefix(`/api`) || PathPrefix(`/dashboard`))"
      - "traefik.http.routers.dashboard.service=api@internal"
      - "traefik.http.routers.dashboard.tls=true"
      - "traefik.http.routers.dashboard.middlewares=auth"
      - "traefik.http.middlewares.auth.basicauth.usersfile=/htpasswd"
    networks:
      - traefik

  whoami:
    image: traefik/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`localhost`) && PathPrefix(`/whoami`)"
      - "traefik.http.routers.whoami.tls=true"
    networks:
      - traefik

networks:
  traefik:
    external: true

具有此静态配置

Traefik/traefik.yaml

api:
  dashboard: true

entrypoints:
  web:
    address: ":80"
  websecure:
    address: ":443"

log:
  level: TRACE

metrics:
  addInternals: true

providers:
  docker:
    endpoint: "unix:///var/run/docker.sock"

这有效,我可以运行

$ curl -sk https://localhost/whoami | head 
Hostname: ea1b0e62d773
IP: 127.0.0.1
IP: ::1
IP: 172.19.0.3
RemoteAddr: 172.19.0.2:37404
GET /whoami HTTP/1.1
Host: localhost
User-Agent: curl/8.9.1
Accept: */*
Accept-Encoding: gzip

我还可以通过

https://localhost/dashboard/
访问 Traefik 仪表板。

但是,如果我添加其他服务,例如邮件坑:

Mailpit/docker-compose.yml

services:
  mailpit:
    image: axllent/mailpit
    container_name: mailpit
    restart: unless-stopped
    volumes:
      - mailpit-data:/data
    ports:
      - 8025:8025
      - 1025:1025
    environment:
      MP_MAX_MESSAGES: 5000
      MP_DATABASE: /data/mailpit.db
      MP_SMTP_AUTH_ACCEPT_ANY: 1
      MP_SMTP_AUTH_ALLOW_INSECURE: 1
    labels:
      - "traefik.http.routers.mailpit.rule=Host(`localhost`) && PathPrefix(`/mailpit`)"
      - "traefik.http.routers.mailpit.tls=true"
      - "traefik.http.routers.mailpit.service=mailpit"
      - "traefik.http.services.mailpit.loadbalancer.server.port=8025"
    networks:
      - traefik

volumes:
  mailpit-data:

networks:
  traefik:
    external: true

通过traefik调用接口会出现404页面未找到

$ curl -sk https://localhost/mailpit | head
404 page not found

但是,该服务已启动并正在运行,我可以通过 http://localhost:8025 访问 mailpit 仪表板,但不能通过 traefik 访问。

但是 traefik 仪表板在 url 处正确列出了 mailpit 服务:http://172.19.0.4:8025 并且在 traefik 服务器本身内访问它工作正常。

$ docker exec -it traefik wget -O - http://172.19.0.4:8025 | head
Connecting to 172.19.0.4:8025 (172.19.0.4:8025)
writing to stdout
<!DOCTYPE html>
<html lang="en" class="h-100">

<head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <meta name="referrer" content="no-referrer">
        <meta name="robots" content="noindex, nofollow, noarchive">

然而,这个输出没有被报告回来。

出了什么问题?

(重写部分,因为 Stack Overflow 认为这是垃圾邮件)

  • Mailpit 启动并在 1025 和 8025 上提供服务。Mailpit 仪表板在 http 8025 上提供服务。在 http://localhost:8025 上运行良好。
  • Traefik 正确向 http://172.19.0.4:8025 报告路由器和服务。
  • 我可以从 traefik 容器中成功连接到 http://172.19.0.4:8025。
  • 不知何故 https://localhost/mailpit 无法建立此连接。

我尝试了不同的设置,但无济于事。

docker containers reverse-proxy traefik portforwarding
1个回答
0
投票
  1. 您确定 Mailpit 具有支持 SSL 流量的必要配置吗?我想如果你尝试一下它可能会产生魅力。

    $ curl -sk http://localhost/mailpit 

  2. 如果我的解决方案[1]没有帮助,您可以尝试修改“Mailpit/docker-compose.yml”文件:

    DELETE this line: - "traefik.http.routers.mailpit.tls=true" 

    ADD this line: - "traefik.http.routers.mailpit.entrypoints=websecure" 

希望您的问题能够得到解决。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.