Proxy

Traefik 的簡單反向代理

  • June 21, 2020

我目前使用 Apache 作為我的 LXD 容器的代理,使用這種設置:

<VirtualHost *:80>
   ServerName example.com
   ProxyRequests off
   ProxyPass / http://10.0.0.142/ retry=0
   ProxyPassReverse / http://10.0.0.142/
   ProxyPreserveHost On
</VirtualHost>

我想切換到traefik。我試過這個配置:

defaultEntryPoints = ["http"]
[entryPoints]
 [entryPoints.http]
 address = ":80"

[backends]
 [backends.backend1]
   [backends.backend1.servers.server1]
      url = "http://10.0.0.142"

[frontends]
 [frontends.frontend1]
     backend = "backend1"
     passHostHeader = true
     [frontends.frontend1.routes.example]
         rule = "Host:example.com"
  • 這兩個是等價的嗎?
  • traefik 配置可以簡化嗎?(刪除不必要的規則)

(注意:我不打算使用 docker,我也不想這樣做。)

您缺少後端類型定義(文件、Docker、Swarm …)。

在您的情況下,只需在您的 conf 文件中添加(或取消註釋)[file],如下所示:

defaultEntryPoints = ["http"]
[entryPoints]
 [entryPoints.http]
 address = ":80"

[file]

[backends]
 [backends.backend1]
   [backends.backend1.servers.server1]
      url = "http://10.0.0.142"

[frontends]
 [frontends.frontend1]
     backend = "backend1"
     passHostHeader = true
     [frontends.frontend1.routes.example]
         rule = "Host:example.com"

引用自:https://serverfault.com/questions/850095