Traefik-具有路径的后端代理

时间:2018-10-29 12:22:41

标签: reverse-proxy traefik

我需要将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

有办法解决吗?

谢谢

1 个答案:

答案 0 :(得分:3)

您可以对前端规则使用ReplacePathRegex进行类似的操作(无需在后端执行任何操作):

PathPrefix:/foo;ReplacePathRegex:^/foo(.*) /bar$$1