我正在使用Apache构建代理,它基于URL代理所有内容 .
我的网络服务器在本地运行: http://proxy
当我导航到 http://proxy/{insert-url-here}
我的服务器代理 http://proxy/{insert-url-here}
到 {insert-url-here}
时,正确加载了html,但未加载资源 .
出现此问题的原因是,使用 http://proxy
作为主机,对从我的服务器发起的所有资源的请求进行了定向 . 我希望请求使用 http://proxy/{insert-url-here}
作为主机URL,因此请求可以找到所有资源 .
我在Apache中的VirtualHost的当前配置非常简单:
ServerAdmin webmaster@company.com
DocumentRoot "C:/proxy/htdocs"
ServerName http://proxy
ServerAlias http://proxy
ErrorLog "logs/error-ssl.log"
CustomLog "logs/access-ssl.log" common
ProxyRequests Off
ProxyPreserveHost On
RequestHeader unset Accept-Encoding
<Location />
Order allow,deny
Allow from all
</Location>
ProxyPassMatch /(.*) http://$1
ProxyPassReverse /(.*) http://$1
Desired solution:
我想正确地将 http://proxy/{insert-url-here}
代理到 {insert-url-here}
. 如果我必须彻底改变我当前的配置并不重要 .
希望你们能帮助我 .
1 回答
我理解你的问题 . 我有一个类似的用例,我在Apache 2.3中测试过它 . 确保禁用ProxyPreserveHost,以便您不会传递当前主机 . 此选项可能会破坏一些动态URL .
您可以使用Mod_rewrite和Mod_proxy的组合来解决其余问题 . 您需要分两部分来解决这个问题 . 您需要代理所有内容,然后修复链接 .
# Fix broken links -> Make sure your requested url is not included RewriteCond %{REQUEST_URI} !(www.*.nl)
# Clever trick to get the requested url out of the HTTP referer and make it available for the %1 variable RewriteCond %{HTTP_REFERER} (www.*.nl)
# Rewrite all requests to your proxy with the base url from the RewriteCond above and the captured group from this rule made available by the captured group by Regex RewriteRule /(.*) http://proxy/%1/$1
# Proxy only if the broken links are fixed RewriteCond %{REQUEST_URI} www.*.nl
# This rule makes sure you proxy everything, this will cause broken links which you have to rewrite RewriteRule /(.*) http://$1 [P]