-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable idle conn counts for connection pooling
- Loading branch information
1 parent
02be81e
commit 4b5025f
Showing
3 changed files
with
115 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,11 @@ $ xcaddy build --with github.com/caddyserver/forwardproxy | |
Most people prefer the [Caddyfile](https://caddyserver.com/docs/caddyfile) for configuration. You can stand up a simple, wide-open unauthenticated forward proxy like this: | ||
|
||
``` | ||
example.com | ||
route { | ||
# UNAUTHENTICATED! USE ONLY FOR TESTING | ||
forward_proxy | ||
example.com { | ||
route { | ||
# UNAUTHENTICATED! USE ONLY FOR TESTING | ||
forward_proxy | ||
} | ||
} | ||
``` | ||
|
||
|
@@ -58,9 +59,11 @@ Because `forward_proxy` is not a standard directive, its ordering relative to ot | |
{ | ||
order forward_proxy before file_server | ||
} | ||
example.com | ||
# UNAUTHENTICATED! USE ONLY FOR TESTING | ||
forward_proxy | ||
example.com { | ||
# UNAUTHENTICATED! USE ONLY FOR TESTING | ||
forward_proxy | ||
} | ||
``` | ||
|
||
to define its position globally; then you don't need `route` blocks. The correct order is up to you and depends on your config. | ||
|
@@ -82,29 +85,32 @@ The `forward_proxy` directive has no default order and must be used within a `ro | |
Here's an example of all properties in use (note that the syntax is subject to change): | ||
|
||
``` | ||
:443, example.com | ||
route { | ||
forward_proxy { | ||
basic_auth user1 0NtCL2JPJBgPPMmlPcJ | ||
basic_auth user2 密码 | ||
ports 80 443 | ||
hide_ip | ||
hide_via | ||
probe_resistance secret-link-kWWL9Q.com # alternatively you can use a real domain, such as caddyserver.com | ||
serve_pac /secret-proxy.pac | ||
dial_timeout 30 | ||
upstream https://user:[email protected] | ||
acl { | ||
allow *.caddyserver.com | ||
deny 192.168.1.1/32 192.168.0.0/16 *.prohibitedsite.com *.localhost | ||
allow ::1/128 8.8.8.8 github.com *.github.io | ||
allow_file /path/to/whitelist.txt | ||
deny_file /path/to/blacklist.txt | ||
allow all | ||
deny all # unreachable rule, remaining requests are matched by `allow all` above | ||
} | ||
} | ||
file_server | ||
forward_proxy { | ||
basic_auth user1 0NtCL2JPJBgPPMmlPcJ | ||
basic_auth user2 密码 | ||
ports 80 443 | ||
hide_ip | ||
hide_via | ||
probe_resistance secret-link-kWWL9Q.com # alternatively you can use a real domain, such as caddyserver.com | ||
serve_pac /secret-proxy.pac | ||
dial_timeout 30 | ||
max_idle_conns 50 | ||
max_idle_conns_per_host 2 | ||
upstream https://user:[email protected] | ||
acl { | ||
allow *.caddyserver.com | ||
deny 192.168.1.1/32 192.168.0.0/16 *.prohibitedsite.com *.localhost | ||
allow ::1/128 8.8.8.8 github.com *.github.io | ||
allow_file /path/to/whitelist.txt | ||
deny_file /path/to/blacklist.txt | ||
allow all | ||
deny all # unreachable rule, remaining requests are matched by `allow all` above | ||
} | ||
} | ||
``` | ||
|
||
|
@@ -200,7 +206,19 @@ route { | |
- `dial_timeout [integer]` | ||
Sets timeout (in seconds) for establishing TCP connection to target website. Affects all requests. | ||
|
||
Default: 20 seconds. | ||
Default: 30 seconds. | ||
|
||
### Pooling | ||
|
||
By default, forwardproxy will reuse connections by using Go's built-in connection pooling mechanism. You can adjust the maximum number of idle connections to keep open: | ||
|
||
- `max_idle_conns [integer]` | ||
Sets the maximum number of idle connections to keep open, globally. Set to -1 for no global limit. See https://pkg.go.dev/net/http#Transport.MaxIdleConns | ||
Default: 50. | ||
|
||
- `max_idle_conns_per_host [integer]` | ||
Sets the maximum number of idle connections to keep open _per host_. See https://pkg.go.dev/net/http#Transport.MaxIdleConnsPerHost | ||
Default: 0, which uses Go's default of 2. | ||
|
||
### Other | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters