docs/en/docs/rules/proxy.md
The proxy (or http-proxy) directive forwards matching requests through a specified HTTP proxy server. These two directives have identical functionality and can be used interchangeably.
pattern proxy://ipOrDomain[:port] [filters...]
# Equivalent:
pattern http-proxy://ipOrDomain[:port] [filters...]
portis optional. If left blank, the default port80will be used.
| Parameters | Description | Detailed Documentation |
|---|---|---|
| pattern | An expression to match the request URL | Match Pattern Documentation |
| value | IP + optional port or domain name + optional port | |
| ⚠️ Loading data from files/remote URLs is not supported | Operation Instruction Documentation | |
| filters | Optional filters. Supports matching: | |
| • Request URL/Method/Headers/Content | ||
| • Response Status Code/Headers | Filter Documentation |
# Proxy requests to the HTTP proxy: `127.0.0.1:80`
www.example.com/path proxy://127.0.0.1 # Default port 80
# Proxy all requests for the current domain to the HTTP proxy: `127.0.0.1:8080`
www.example.com proxy://127.0.0.1:8080
# You can also use a domain name.
www.example.com/path proxy://test.proxy.com # Default port 80
www.example.com proxy://test.proxy.com:8080
After proxying a request to the upstream proxy, by default the upstream proxy will use DNS to obtain the server IP address based on the requested domain name before continuing the request. If you want the upstream proxy to continue the request based on a specific IP address and port, you can do this:
# Using query parameters
www.example.com proxy://127.0.0.1:8080?host=1.1.1.1
www.example.com proxy://127.0.0.1:8080?host=1.1.1.1:8080
# Enable via directive
www.example.com proxy://127.0.0.1:8080 1.1.1.1 enable://proxyHost
www.example.com proxy://127.0.0.1:8080 1.1.1.1:8080 enable://proxyHost
1.1.1.1is equivalent tohost://1.1.1.1
hostWhen a request matches both host and proxy rules:
host rule takes effectproxy rule is automatically ignored| Configuration Method | Syntax | Effect |
|---|---|---|
| Prioritize proxy | enable://proxyFirst or lineProps://proxyFirst | Only proxy takes effect (overrides host) |
| Both take effect | enable://proxyHost or lineProps://proxyHost | Both proxy and host take effect |
proxyFirst only when special proxy logic is requiredproxyHost when dual matching is requiredThe host protocol only applies to the substituted URL (i.e., the Final URL shown in the Overview). If the Final URL is empty, it will take effect on the original request URL.
For example, with the rule:
www.example.com/api www.example.com 127.0.0.1:1234
A request to https://www.example.com/api/path will be processed by Whistle, and the Final URL becomes https://www.example.com/path. As a result, it will not match 127.0.0.1:1234.
If you want to match the substituted request, you can modify the rules as follows:
www.example.com/api www.example.com
www.example.com 127.0.0.1:1234