我一直在尝试在我托管在 Hostgator Centos 服务器上的网站上复制 ProxyPass 和 ProxyPassReverse。我有一个在 Amazon ec2 上运行的 tomcat 应用程序,URL 为 http://myec2address.com:8080/portal/
我在 httpd-proxy-html 文件上使用以下配置成功地在本地 Windows 机器上复制了用例。
ProxyPass/portalBI http://{localhost}:8080/poratalBI
ProxyPass/sw-style http://{localhost}:8080/sw-style
ProxyPass/portal-style http://{localhost}:8080/portal-style
ProxyPassReverse/portalBI http://{localhost}:8080/agrometricsBI
ProxyPassReverse/sw-style http://{localhost}:8080/sw-style
ProxyPassReverse/portal-style http://{localhost}:8080/portal-style
由于托管网站位于共享服务器上,我假设我将不得不修改我的 .htaccess 文件。我尝试了很多技巧但没有成功。你能帮忙吗?由于 centOS,我们需要处理特殊字符吗?
谢谢。
最佳答案
您不能在 htaccess 文件中使用 ProxyPass
或 ProxyPassReverse
。您可以做的最好的事情是使用 mod_rewrite 的 P
标志进行反向代理(相当于 ProxyPass
):
RewriteEngine On
RewriteRule ^portalBI(.*)$ http://localhost:8080/poratalBI$1 [L,P]
RewriteRule ^sw-style(.*)$ http://localhost:8080/sw-style$1 [L,P]
RewriteRule ^portal-style(.*)$ http://localhost:8080/portal-style$1 [L,P]
除非您的共享主机加载了 mod_proxy,否则这不会起作用,而且您不会像使用 ProxyPassReverse
那样获得反向位置重写。
关于apache - centOS htaccess 文件上的 Proxypass 和 ProxyPassReverse 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23238703/