我正在用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 [email protected]
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
所需的解决方案:
我想http://proxy/{insert-url-here}
正确地代理{insert-url-here}
。是否必须完全更改当前配置并不重要。
希望你们能帮助我。
我了解您的问题。我有一个类似的用例,并且已经在Apache 2.3中进行了测试。确保禁用ProxyPreserveHost,以免传递当前主机。此选项可能会破坏一些动态网址。
您可以通过结合使用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]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句