将traefik用作Docker和非Docker服务的反向代理

时间:2019-04-17 08:18:58

标签: reverse-proxy traefik

我目前正在尝试将Traefik设置为路由到位于8080和5000端口上10.0.1.4的另一台计算机上的多个docker容器和多个非docker应用程序

到目前为止,我已经获得了Traefik仪表板,并且让我们与docker应用程序一起加密并运行,但是我无法让外部应用程序转发到另一台机器上

这是我的traefik.toml

defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.dashboard]
    address = ":8080"
    [entryPoints.dashboard.auth]
      [entryPoints.dashboard.auth.basic]
        users = ["admin:xxxx"]
  [entryPoints.http]
    address = ":80"
      [entryPoints.http.redirect]
        entryPoint = "https"
  [entryPoints.https]
    address = ":443"
      [entryPoints.https.tls]

[api]
entrypoint="dashboard"

[acme]
email = "xxx@example.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
  [acme.httpChallenge]
  entryPoint = "http"

[docker]
domain = "example.com"
watch = true
network = "web"


[file]

[backends]

  # Set name of backend describing Rancher. We name it "app1".
  [backends.app1]

    [backends.app1.servers]

      [backends.app1.servers.server0]

        # URL to app1 server.
        url = "http://10.0.1.4:5000"

        # As this is a single instance app1, we can set the weight to 1. All requests will be handled by this server.
        weight = 1

  # Set name of backend describing Rancher. We name it "app2".
  [backends.app2]

    [backends.app2.servers]

      [backends.app2.servers.server0]

        # URL to app2 server.
        url = "http://10.0.1.4:8181"

        # As this is a single instance app2, we can set the weight to 1. All requests will be handled by this server.
        weight = 1


[frontends]

  # Set name of frontend describing app1. We use the same name "app1".
  [frontends.app1]

    # Backend which will handle requests.
    backend = "app1"

    # Forward client Host header to the backend.
    passHostHeader = true

      [frontends.app1.routes]

        [frontends.app1.routes.route0]

          # Use this frontend only when the request contains Host header with our domain.
          rule = "Host:application1.example.com"

  # Set name of frontend describing app2. We use the same name "app2".
  [frontends.app2]

    # Backend which will handle requests.
    backend = "app2"

    # Forward client Host header to the backend.
    passHostHeader = true

      [frontends.app2.routes]

        [frontends.app2.routes.route1]

          # Use this frontend only when the request contains Host header with our domain.
          rule = "Host:application2.example.com"

这是我的docker-compose.yml代码

version: "3"

networks:
  web:
    external: true
  internal:
    external: false

我希望我的域名进入application1.example.com和application2.example.com。任何帮助,将不胜感激。谢谢!

0 个答案:

没有答案