Traefik的简单反向代理


10

我目前正在使用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,但我不想这样做。)

Answers:


19

您缺少后端类型定义(文件,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"

2
那么[file]是必需的吗?我什么都没找到。为什么会这样呢?
lepe

1
是的,如果您只是想在配置文件中静态手动创建规则。您可以参考以下文档:https
//docs.traefik.io/toml/#file-backend

好。得到它了。谢谢!(您介意否决我的问题吗?不确定为什么会
否决

1
好问题-在那里呆了一个小时...
andig '18

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.