hel*_*y77 2 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;
}
}
Run Code Online (Sandbox Code Playgroud)
我会将其转换为 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
Run Code Online (Sandbox Code Playgroud)
有办法解决吗?
谢谢
您可以使用 ReplacePathRegex 作为前端规则执行类似的操作(无需在后端执行任何操作):
PathPrefix:/foo;ReplacePathRegex:^/foo(.*) /bar$$1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3794 次 |
| 最近记录: |