首页 > 解决方案 > Traefik 中使用本地插件时中间件不存在

问题描述

我试图在相关帖子中找到答案,但我找不到它。

我创建了一个本地插件并以这种方式配置它:

traefik.toml

[experimental.localPlugins.myplugin]
moduleName = "test.com/traefik/myplugin"

.traefik.yml

displayName: Do some stuff
type: middleware
import: test.com/traefik/myplugin
summary:do a lot of nice stuffs

testData:
  Headers:
    Foo: Bar

我可以在日志中看到插件已加载:

Static configuration loaded {"global":{"checkNewVersion":true},"serversTransport":{"maxIdleConnsPerHost":200},"entryPoints":{"http":{"address":":80","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}},"traefik":{"address":":8080","transport":{"lifeCycle":{"graceTimeOut":"10s"},"respondingTimeouts":{"idleTimeout":"3m0s"}},"forwardedHeaders":{},"http":{},"udp":{"timeout":"3s"}}},"providers":{"providersThrottleDuration":"2s","docker":{"watch":true,"endpoint":"unix:///var/run/docker.sock","defaultRule":"Host(`{{ normalize .Name }}`)","exposedByDefault":true,"swarmModeRefreshSeconds":"15s"}},"api":{"insecure":true,"dashboard":true},"ping":{"entryPoint":"http","terminatingStatusCode":503},"log":{"level":"DEBUG","format":"common"},"accessLog":{"format":"json","filters":{},"fields":{"defaultMode":"keep","headers":{"defaultMode":"drop"}}},"pilot":{"dashboard":true}**,"experimental":{"localPlugins":{"myplugin":{"moduleName":"test.com/traefik/myplugin"}}}}

但是当我尝试像这样使用它时:

traefik.http.routers.myrouter.middlewares="testplugin-myplugin"

或者

traefik.http.routers.myrouter.middlewares="myplugin"

我收到如下错误:

middleware "testplugin-mypluginn@docker" does not exist

我正在使用 Traefik 2.5.2 docker image> 我尝试了一些静态和动态值的组合但没有运气:(我正在使用 Traefik 2.5.2 docker image。我尝试了一些静态和动态值的组合但没有运气:(我错过了一些配置吗?

标签: middlewaretraefik

解决方案


在文件中创建中间件时需要引用@file。否则,您会看到它正在寻找 testplugin-myplugin@docker,这意味着中间件是在 docker 规则中构建的。

尝试类似:

traefik.http.routers.myrouter.middlewares="myplugin@file" 

推荐阅读