首页 > 解决方案 > https://www 上的 Traefik 404

问题描述

我正在使用这个配置:

version: "3.3"
services:
  traefik:
    command:
      # Get Docker as the provider
      - "--providers.docker=true"
      # Avoid that all containers are exposed
      - "--providers.docker.exposedbydefault=false"
      # Settle the ports for the entry points
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web-secure.address=:443"
      # Settle the autentification method to http challenge
      - "--certificatesresolvers.myhttpchallenge.acme.httpchallenge=true"
      - "--certificatesresolvers.myhttpchallenge.acme.httpchallenge.entrypoint=web"
      # Uncomment this to get a fake certificate when testing
      #- "--certificatesresolvers.myhttpchallenge.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory"
      # Settle letsencrypt as the certificate provider
      - "--certificatesresolvers.myhttpchallenge.acme.email=___________________
      - "--certificatesresolvers.myhttpchallenge.acme.storage=/letsencrypt/acme.json"
  mysite:
    labels:
      # The labels are usefull for Traefik only
      - "traefik.enable=true"
      - "traefik.docker.network=traefik"
      # Get the routes from http
      - "traefik.http.routers.mysite.rule=Host(mysite.com, www.mysite.com)"
      - "traefik.http.routers.mysite.entrypoints=web"
      # Redirect these routes to https
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.mysite.middlewares=redirect-to-https@docker"
      # Get the routes from https
      - "traefik.http.routers.mysite-secured.rule=Host(mysite.com, www.mysite.com)"
      - "traefik.http.routers.mysite-secured.entrypoints=web-secure"
      # Apply autentificiation with http challenge
      - "traefik.http.routers.mysite-secured.tls=true"
      - "traefik.http.routers.mysite-secured.tls.certresolver=myhttpchallenge"

一切正常,除了 https://www。我收到一个 SSL 错误,然后当我仍然单击继续时,我从 traefik 收到一个错误,找不到 404 页面。http://、https://、http://www 都可以,重定向到 https://。但是 https://www 不起作用。

我尝试了很多建议,正则表达式中间件没有成功。这只是完全相同的结果。

标签: traefik

解决方案


我需要在 Host() 中的站点名称周围添加反引号:

- "traefik.http.routers.mysite.rule=Host(`mysite.com`, `www.mysite.com`)"
- "traefik.http.routers.mysite-secured.rule=Host(`mysite.com`, `www.mysite.com`)"

另外,我的部署是错误的。有时我会临时上传文件,然后手动运行一个用旧版本覆盖的 post-receive 挂钩。


推荐阅读