我尝试在Docker主机上的容器中设置traefik:主机:myserver.some.domain Traefik:v2.1.3 Docker主机:v19.03.8下载
当我请求“http://myserver.some.domain/traefik“时,我想查看 Jmeter 板,进一步的导航应该反映在URL中,比如请求第一个URL并登陆“http://myserver.some.domain/traefik/dashboard/#/“。
- 路径
- 路径前缀
- 带前缀
到目前为止,PathPrefix听起来像是最正确的选择,但我得到的是“404页面未找到”。现在我还公开了端口8080,所以我可以交叉检查我的更改(在http://myserver.some.domain:8080上,它可以工作)。稍后,我想隐藏端口8080,只让端口80上的路由完成工作。
我的docker-compose.yml看起来像这样:
version: "3"
services:
traefik:
image: traefik:2.1.3
container_name: 'traefik'
command:
# Enable DEBUG log for issue resolving
- "--log.level=DEBUG"
# Enable dashboard
- "--api.dashboard=true"
# Enable debug information in api
- "--api.debug=true"
# Allow api access on unsecure http requests
# Will be removed when SSL will be configured
- "--api.insecure=true"
# Default http port
- "--entrypoints.web.address=:80"
# Dashboard port
- "--entrypoints.traefik.address=:8080"
# Allow traefik to se other docker containers for dynamic routing
- "--providers.docker.endpoint=unix:///var/run/docker.sock"
# Hide containers without traefik configuration by default
- "--providers.docker.exposedByDefault=false"
# Use the container's configured network
# All containers use network "proxy", type "bridge"
- "--providers.docker.useBindportIP=false"
labels:
# Enable Traefik configuration for container
traefik.enable: "true"
# Use docker network "proxy"
traefik.docker.network: "proxy"
# Define http entrypoint
traefik.http.routers.traefik.entrypoints: "web"
# Proxy all requests which start with "/traefik"
traefik.http.routers.traefik.rule: "PathPrefix(`/traefik`)"
# # Proxy request on path "/traefik"
# traefik.http.routers.traefik.rule: "Path(`/traefik`)"
# Replace path prefix "/traefik" with "/"
traefik.http.routers.traefik.middlewares: "traefik_replacepath"
traefik.http.middlewares.traefik_replacepath.replacePath.path: "/"
# # Strip path prefix "/traefik" and force slash "/"
# traefik.http.routers.traefik.middlewares: "traefik_stripprefix"
# traefik.http.middlewares.traefik_stripprefix.stripprefix.prefices: "/traefik"
# traefik.http.middlewares.traefik_stripprefix.stripPrefix.forceSlash: "true"
# Define port for service
traefik.http.services.traefik.loadbalancer.server.port: "8080"
volumes:
# Allow traefik to see other containers
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- proxy
ports:
# Expose port 80 to handle web/http requests
- "80:80"
# For DEBUG: Expose port 8080 to see dashboard without routing
# Will be removed when default rounting is working
- "8080:8080"
networks:
proxy:
external: true
有人知道我错在哪里吗?
最好的问候,大卫
1条答案
按热度按时间vsikbqxv1#
您应该使用Traefik提供的stripprefix plugin。
在你的例子中,标签应该是这样的:
基本上,通过
PathPrefix
规则,您可以设置要路由此服务的路径。然后在使用stripprefix
插件将请求发送到服务之前删除此路径。如果您通过这些标签将其他服务连接到traefik,请确保它们共享同一网络。