reverse_proxy
最后更新于:2022-04-02 02:56:03
[TOC]
## reverse_proxy
> [官网手册](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy)
该指令的作用有
- 代理传输
- 负载平衡
- 运行状况检查
- 标头处理
-缓冲选项
- 向一个或多个后端发出请求
语法
```
reverse_proxy [] [] {
# 后端
to
...
#负载平衡
lb_policy []
lb_try_duration
lb_try_interval
# 主动健康检查
health_path
health_port
health_interval
health_timeout
health_status
health_body
# 被动健康检查
fail_duration
max_fails
unhealthy_status
unhealthy_latency
unhealthy_request_count
# 流媒体
flush_interval
# 标头处理
header_up [+|-] [ []]
header_down [+|-] [ []]
# round trip
transport {
...
}
}
```
### 实例
```
reverse_proxy localhost:9005
# 反向代理到 https
reverse_proxy https://example.com
# 负载均衡
reverse_proxy node1:80 node2:80 node3:80
# 对指定api负载均衡
reverse_proxy /api/* node1:80 node2:80 node3:80 {
lb_policy header X-My-Header
}
# 删除路径前缀,然后代理
route /prefix/* {
uri strip_prefix /prefix
reverse_proxy localhost:9000
}
```
';