【问题标题】:Apache proxy: Proxy based on urlApache 代理:基于 url 的代理
【发布时间】:2015-09-11 21:09:48
【问题描述】:

我正在使用 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

所需的解决方案:

我想将http://proxy/{insert-url-here} 正确代理到{insert-url-here}。如果我必须完全改变我当前的配置也没关系。

希望你们能帮帮我。

【问题讨论】:

    标签: apache http url mod-rewrite proxy


    【解决方案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]

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 2013-11-30
      • 2019-06-20
      • 1970-01-01
      • 2011-07-13
      • 2015-02-06
      相关资源
      最近更新 更多