🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## reverse_proxy > [官网手册](https://caddyserver.com/docs/caddyfile/directives/reverse_proxy) 该指令的作用有 - 代理传输 - 负载平衡 - 运行状况检查 - 标头处理 -缓冲选项 - 向一个或多个后端发出请求 语法 ``` reverse_proxy [<matcher>] [<upstreams...>] { # 后端 to <upstreams...> ... #负载平衡 lb_policy <name> [<options...>] lb_try_duration <duration> lb_try_interval <interval> # 主动健康检查 health_path <path> health_port <port> health_interval <interval> health_timeout <duration> health_status <status> health_body <regexp> # 被动健康检查 fail_duration <duration> max_fails <num> unhealthy_status <status> unhealthy_latency <duration> unhealthy_request_count <num> # 流媒体 flush_interval <duration> # 标头处理 header_up [+|-]<field> [<value|regexp> [<replacement>]] header_down [+|-]<field> [<value|regexp> [<replacement>]] # round trip transport <name> { ... } } ``` ### 实例 ``` 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 } ```