我刚刚添加并提交了对 mod_proxy_core 的头部重写支持。
$HTTP["url"] =~ "^/proxyme(/|$)" {
proxy-core.balancer = "round-robin"
proxy-core.protocol = "http"
proxy-core.backends = ( "en.wikipedia.org" )
proxy-core.rewrite-response = (
"Location" => ( "^http://en.wikipedia.org/(.*)" => "http://127.0.0.1:1025/proxyme/$1" ),
)
proxy-core.rewrite-request = (
"_uri" => ( "^/proxyme/?(.*)" => "/$1" ),
"Host" => ( ".*" => "en.wikipedia.org" ),
)
}
wget 现在运行正常,并通过代理按预期跟踪重定向
$ wget http://127.0.0.1:1025/proxyme/
--15:18:20-- http://127.0.0.1:1025/proxyme/
=> `index.html.1'
Connecting to 127.0.0.1:1025... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://127.0.0.1:1025/proxyme/wiki/Main_Page [following]
--15:18:20-- http://127.0.0.1:1025/proxyme/wiki/Main_Page
=> `Main_Page'
Connecting to 127.0.0.1:1025... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
...
这以一种非常通用的方式实现了“ProxyPassReverse”:https://httpd.apache.ac.cn/docs/1.3/mod/mod_proxy.html#proxypassreverse。“ProxyPass”:https://httpd.apache.ac.cn/docs/1.3/mod/mod_proxy.html#proxypass 与请求中的 Host: 重写相同。一切都通过 URL 条件控制,并将代理限制在
/proxyme/ URL。