大佬教程收集整理的这篇文章主要介绍了linux – 如何使用反向代理正确处理相对URL,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
地址为www.example.com/folder的服务器A是反向代理服务器.
它映射到:服务器B,地址为test.madeupurl.com
这种作品.但我遇到的问题是,在www.example.com/folder上,所有相关链接都是www.example.com/css/examplefilename.css而不是www.example.com/folder/css/examplefilename. CSS
我该如何解决?
到目前为止,我的反向代理在服务器A(www.example.com)上有这个:
<LOCATIOn /folder> ProxyPass http://test.madeupurl.com ProxyPassReverse http://test.madeupurl.com </LOCATIOn>
许多替代方案:
一)重写内部应用程序以使用相对路径而不是绝对路径. ie ../css/style.css而不是/css/style.css
2)将内部应用程序重新部署在同一子目录/文件夹中,而不是在test.example.com的根目录中.
三)一两个通常不太可能发生…如果你很幸运,内部应用程序只使用两个或三个子目录,而在主站点上没有使用它们,只需编写一堆ProxyPass行:
# ExposE internal App to thE internet. ProxyPass /externalpath/ http://test.example.com/ ProxyPassReverse /externalpath/ http://test.example.com/ # Internal app uses a bunch of absolute paths. ProxyPass /css/ http://test.example.com/css/ ProxyPassReverse /css/ http://test.example.com/css/ ProxyPass /icons/ http://test.example.com/icons/ ProxyPassReverse /icons/ http://test.example.com/icons/
四)为内部应用程序创建一个单独的子域,并简单地反向代理所有内容:
<VirtualHost *:80> ServerName app.example.com/ # ExposE internal App to thE internet. ProxyPass / http://test.internal.example.com/ ProxyPassReverse / http://test.internal.example.com/ </VirtualHost>
五)有时开发人员完全无能为力,他们的应用程序不仅生成绝对URL,而且甚至在其URL中包含主机名部分,生成的HTML代码如下所示:< img src = http://test.example.com/icons /logo.png\u0026gt ;. A)您可以使用水平分割DNS和方案4的组合解决方案.内部和外部用户都使用test.example.com,但您的内部DNS直接指向test.example.com服务器的ip地址.对于外部用户,test.example.com的公共记录指向公共网络服务器www.example.com的IP地址,然后您可以使用解决方案4. B)您实际上可以获得apache,不仅可以代理对test.example.com的请求,还可以在将响应主体传输给您的用户之前重写它. (通常,代理仅重写http标头/响应). apache 2.2中的mod_substitute.我没有测试它是否与mod_proxy很好地堆叠,但可能以下工作:
<LOCATIOn /folder/> ProxyPass http://test.example.com/ ProxyPassReverse http://test.example.com/ AddOutputFilterByType SUBSTITUTE text/html Substitute "s|test.example.com/|www.example.com/folder/|i" </LOCATIOn>
以上是大佬教程为你收集整理的linux – 如何使用反向代理正确处理相对URL全部内容,希望文章能够帮你解决linux – 如何使用反向代理正确处理相对URL所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。