traefik启动后默认会使用8080端口来监听dashboard访问,为了减少端口的暴露,可以使用80端口+路径来转发dashboard请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Dynamic Configuration http: routers: dashboard: rule: PathPrefix(`/dashboard`)) service: api@internal middlewares: - auth middlewares: auth: basicAuth: users: - "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/" - "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0" |
basicAuth的用户名密码可以通过https://hostingcanada.org/htpasswd-generator/生成
这里有一个坑,如果直接用http://your-ip-address/dashboard访问会提示404 page not found
正确的访问路径是http://your-ip-address/dashboard/
该部分内容的官方文档:https://doc.traefik.io/traefik/operations/dashboard/
同理,暴露api接口也是同样的配置,修改上方rule为
1 |
rule = "PathPrefix(`/api`) || PathPrefix(`/dashboard`)" |
这时直接访问http://your-ip-address/api还是会显示404 page not found
原因是api需要有具体的请求路径才会有返回内容,参考:https://doc.traefik.io/traefik/operations/api/#endpoints
例如需要访问这样的地址,http://your-ip-address/api/http/routers,会返回所有routers的信息
There are no comments yet