首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Traefik版本2只显示404或根本没有网站。

Traefik版本2只显示404或根本没有网站。
EN

Stack Overflow用户
提问于 2019-09-27 16:50:52
回答 1查看 35.2K关注 0票数 15

我尝试在第2版中设置Traefik,但我只在浏览器中得到"404 Page“或DNS_PROBE_FINISHED_NXDOMAIN错误。

当我检查路由器的API端点时,我可以看到我的两个容器是在Traefik中启用的,并且规则是正确的。

代码语言:javascript
运行
复制
curl http://localhost:8080/api/http/routers

[{"entryPoints":["web","secure"],"service":"gotify-gotify","rule":"Host(`sub2.example.org`)","tls":{"certResolver":"letsencrypt"},"status":"enabled","using":["secure","web"],"name":"gotify@docker","provider":"docker"},{"entryPoints":["web","secure"],"service":"nextcloud-cloud","rule":"Host(`sub.example.org`)","tls":{"certResolver":"letsencrypt"},"status":"enabled","using":["secure","web"],"name":"nextcloud@docker","provider":"docker"}]

但在"sub2“上,我根本没有网站,而在”子“上,我得到了"404页找不到”。我已经为"*“设置了DNS条目,所以所有子域都会转到同一台服务器上。

我已经为码头集装箱设置了下列标签

代码语言:javascript
运行
复制
labels:
traefik.enable: true
traefik.http.routers.nextcloud.rule: "Host(`sub.example.org`)"
traefik.http.routers.nextcloud.entrypoints: "web, secure"
traefik.http.routers.nextcloud.tls.certresolver: "letsencrypt"

这是我的Traefik配置traefik.toml

代码语言:javascript
运行
复制
[entryPoints]
  [entryPoints.web]
    address = ":80"
  [entryPoints.secure]
    address = ":443"

[providers.docker]
  exposedByDefault = false
  network = "traefik"

[certificatesResolvers.letsencrypt.acme]
  email = "me@example.org"
  storage = "acme.json"
  [certificatesResolvers.letsencrypt.acme.httpChallenge]
    entryPoint = "web"

[api]
  insecure = true
  debug = true
  dashboard = false

Traefik本身就是一个码头集装箱。

代码语言:javascript
运行
复制
version: "3.7"

services:
  traefik:
    image: traefik:v2.0
    container_name: traefik
    restart: unless-stopped
    volumes:
    - "./traefik.toml:/etc/traefik/traefik.toml"
    - "./acme:/etc/traefik/acme"
    - "/var/run/docker.sock:/var/run/docker.sock"
    ports:
    - "80:80"
    - "127.0.0.1:8080:8080"
    - "443:443"
    networks:
    - traefik

networks:
  traefik:
    driver: bridge
    name: traefik

我使用ufw管理防火墙规则,并打开端口22、80和443。

代码语言:javascript
运行
复制
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
EN

回答 1

Stack Overflow用户

发布于 2019-10-03 09:03:28

您可以找到traefik 2.2.1的工作示例。也可以检查完整的设置要点:https://gist.github.com/fatihyildizhan/8f124039a9bd3801f0caf3c01c3601fb

我更喜欢在2.0版中使用traefik.yml。它看起来很简单,很多人都很熟悉YAML文件。

代码语言:javascript
运行
复制
[Traefik v2.0] - docker-compose.yml  with httpChallenge

    version: '3.7'

    services:
      traefik:
        image: traefik:v2.2.1
        container_name: traefik
        restart: unless-stopped
        security_opt:
          - no-new-privileges:true
        networks:
          - proxy
        ports:
          - 80:80
          - 443:443
        volumes:
          - /etc/localtime:/etc/localtime:ro
          - /var/run/docker.sock:/var/run/docker.sock:ro
          - ./traefik.yml:/traefik.yml:ro
          - ./acme.json:/acme.json
        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.traefik.entrypoints=http"
          - "traefik.http.routers.traefik.rule=Host(`traefik.your-domain.com`)"
          - "traefik.http.middlewares.traefik-auth.basicauth.users=username:hashed-password"
          - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
          - "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
          - "traefik.http.routers.traefik-secure.entrypoints=https"
          - "traefik.http.routers.traefik-secure.rule=Host(`traefik.your-domain.com`)"
          - "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
          - "traefik.http.routers.traefik-secure.tls=true"
          - "traefik.http.routers.traefik-secure.tls.certresolver=http"
          - "traefik.http.routers.traefik-secure.service=api@internal"
          - "traefik.http.services.traefik.loadbalancer.server.port=8080"

    networks:
      proxy:
        external: true


    [Traefik v2.0] - traefik.yml with httpChallenge

    api:
      dashboard: true

    # Writing Logs to a File, in JSON
    log:
      level: DEBUG
      filePath: "log-file.log"
      format: json

    # Configuring a buffer of 100 lines
    accessLog:
      filePath: "log-access.log"
      bufferingSize: 100  

    entryPoints:
      http:
        address: ":80"
      https:
        address: ":443"

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

    certificatesResolvers:
      http:
        acme:
          email: your-email.com
          storage: acme.json
          httpChallenge:
            entryPoint: http    


    [Traefik v2.0] - your-container docker-compose.yml

    version: '3.7'

    services:
        your-container-name:
          image: docker.pkg.github.com/username/repo-name/image-name:latest
          container_name: your-container-name
          restart: unless-stopped
          security_opt:
            - no-new-privileges:true
          networks:
            - proxy
          volumes:
            - /etc/localtime:/etc/localtime:ro
            - /var/run/docker.sock:/var/run/docker.sock:ro
            - ./data:/data
          labels:
            - "traefik.enable=true"
            - "traefik.http.routers.your-container-name.entrypoints=http"
            - "traefik.http.routers.your-container-name.rule=Host(`your-container-name.your-domain.com`)"
            - "traefik.http.middlewares.your-container-name-https-redirect.redirectscheme.scheme=https"
            - "traefik.http.routers.your-container-name.middlewares=your-container-name-https-redirect"
            - "traefik.http.routers.your-container-name-secure.entrypoints=https"
            - "traefik.http.routers.your-container-name-secure.rule=Host(`your-container-name.your-domain.com`)"
            - "traefik.http.routers.your-container-name-secure.tls=true"
            - "traefik.http.routers.your-container-name-secure.tls.certresolver=http"
            - "traefik.http.routers.your-container-name-secure.service=your-container-name"
            - "traefik.http.services.your-container-name.loadbalancer.server.port=80"
            - "traefik.docker.network=proxy"

    networks:
      proxy:
        external: true
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58138650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档