2
votes

i need to proxy http://www.example.com/foo to http://<backend>/bar, with nginx i have this configuration:

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;
    }
}

I would convert this to traefik. there my compose file:

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

is there a way to solve?

Thanks

1

1 Answers

4
votes

You could do something like that using ReplacePathRegex for the frontend rule (no need to do anything on backend):

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