@@ -1075,7 +1075,7 @@ following `Nginx` config:
10751075
10761076``` console
10771077location /get {
1078- proxy_pass http://httpbin.org/get
1078+ proxy_pass http://httpbin.org/get;
10791079}
10801080```
10811081
@@ -1094,6 +1094,36 @@ Verify using `curl -v localhost:8899/get`:
10941094}
10951095```
10961096
1097+ #### Rewrite Host Header
1098+
1099+ With above example, you may sometimes see:
1100+
1101+ ``` console
1102+ >
1103+ * Empty reply from server
1104+ * Closing connection
1105+ curl: (52) Empty reply from server
1106+ ```
1107+
1108+ This is happenening because our default reverse proxy plugin ` ReverseProxyPlugin ` is configured
1109+ with a ` http ` and a ` https ` upstream server. And, by default ` ReverseProxyPlugin ` preserves the
1110+ original host header. While this works with ` https ` upstreams, this doesn't work reliably with
1111+ ` http ` upstreams. To work around this problem use the ` --rewrite-host-header ` flags.
1112+
1113+ Example:
1114+
1115+
1116+ ``` console
1117+ ❯ proxy --enable-reverse-proxy \
1118+ --plugins proxy.plugin.ReverseProxyPlugin \
1119+ --rewrite-host-header
1120+ ```
1121+
1122+ This will ensure that ` Host ` header field is set as ` httpbin.org ` and works with both ` http ` and
1123+ ` https ` upstreams.
1124+
1125+ > NOTE: Whether to use ` --rewrite-host-header ` or not depends upon your use-case.
1126+
10971127## Plugin Ordering
10981128
10991129When using multiple plugins, depending upon plugin functionality,
@@ -2613,7 +2643,7 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT]
26132643 [--proxy-pool PROXY_POOL] [--enable-web-server]
26142644 [--enable-static-server] [--static-server-dir STATIC_SERVER_DIR]
26152645 [--min-compression-length MIN_COMPRESSION_LENGTH]
2616- [--enable-reverse-proxy] [--enable-metrics]
2646+ [--enable-reverse-proxy] [--rewrite-host-header] [-- enable-metrics]
26172647 [--metrics-path METRICS_PATH] [--pac-file PAC_FILE]
26182648 [--pac-file-url-path PAC_FILE_URL_PATH]
26192649 [--cloudflare-dns-mode CLOUDFLARE_DNS_MODE]
@@ -2622,7 +2652,7 @@ usage: -m [-h] [--tunnel-hostname TUNNEL_HOSTNAME] [--tunnel-port TUNNEL_PORT]
26222652 [--filtered-client-ips FILTERED_CLIENT_IPS]
26232653 [--filtered-url-regex-config FILTERED_URL_REGEX_CONFIG]
26242654
2625- proxy.py v2.4.6.dev25+g2754b928.d20240812
2655+ proxy.py v2.4.8.dev8+gc703edac.d20241013
26262656
26272657options:
26282658 -h, --help show this help message and exit
@@ -2791,6 +2821,9 @@ options:
27912821 response that will be compressed (gzipped).
27922822 --enable-reverse-proxy
27932823 Default: False. Whether to enable reverse proxy core.
2824+ --rewrite-host-header
2825+ Default: False. If used, reverse proxy server will
2826+ rewrite Host header field before sending to upstream.
27942827 --enable-metrics Default: False. Enables metrics.
27952828 --metrics-path METRICS_PATH
27962829 Default: /metrics. Web server path to serve proxy.py
0 commit comments