Traefik - 使用路径代理到后端
Traefik - proxy to backend with path
我需要代理 http://www.example.com/foo
到 http://<backend>/bar
,使用 nginx 我有这个配置:
server {
listen 80;
client_max_body_size 2048M;
server_name www.example.com;
location /foo {
proxy_pass http://container_name/bar/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
我会将其转换为 traefik。有我的撰写文件:
version: '3'
services:
traefik:
image: traefik:1.7.3-alpine
command: --api --docker
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- traefik.enable=false
webapp:
...
...
labels:
- traefik.backend=bar
- traefik.frontend.rule=Host:www.example.com;Path:/foo/
- traefik.port=80
有什么办法可以解决吗?
谢谢
您可以对前端规则使用 ReplacePathRegex 来做类似的事情(不需要在后端做任何事情):
PathPrefix:/foo;ReplacePathRegex:^/foo(.*) /bar$
我需要代理 http://www.example.com/foo
到 http://<backend>/bar
,使用 nginx 我有这个配置:
server {
listen 80;
client_max_body_size 2048M;
server_name www.example.com;
location /foo {
proxy_pass http://container_name/bar/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
我会将其转换为 traefik。有我的撰写文件:
version: '3'
services:
traefik:
image: traefik:1.7.3-alpine
command: --api --docker
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
labels:
- traefik.enable=false
webapp:
...
...
labels:
- traefik.backend=bar
- traefik.frontend.rule=Host:www.example.com;Path:/foo/
- traefik.port=80
有什么办法可以解决吗?
谢谢
您可以对前端规则使用 ReplacePathRegex 来做类似的事情(不需要在后端做任何事情):
PathPrefix:/foo;ReplacePathRegex:^/foo(.*) /bar$