Apache 代理 cookie 仅适用于第一个应用程序
坚持将 apache 配置为在不同 PC 上的 tomcat 上运行的应用程序的代理。一切似乎都在第一个应用程序 - WebApp1 上运行。但左边的 ProxyPassReverseCookiePath 不起作用。 ProxyPassReverseCookiePath 仅适用于第一个应用程序。当访问其他应用程序时,jsessionid 会添加到 url 中。 我错过了什么以及如何修复 WebApp2 和 WebApp3?感谢
httpd-vhosts.con:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ProxyRequests off
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /WebApp1/ ajp://192.168.1.98:8009/WebApp1/
ProxyPassReverse /WebApp1/ ajp://192.168.1.98:8009/WebApp1/
ProxyPassReverse /WebApp1/ http://192.168.1.98:8080/WebApp1/
ProxyPassReverseCookiePath /WebApp1 /WebApp1/
ProxyPass /WebApp2/ ajp://192.168.1.98:8009/WebApp2/
ProxyPassReverse /WebApp2/ ajp://192.168.1.98:8009/WebApp2/
ProxyPassReverse /WebApp2/ http://192.168.1.98:8080/WebApp2/
ProxyPassReverseCookiePath /WebApp2 /WebApp2/
ProxyPass /WebApp3/ ajp://192.168.1.98:8009/WebApp3/
ProxyPassReverse /WebApp3/ ajp://192.168.1.98:8009/WebApp3/
ProxyPassReverse /WebApp3/ http://192.168.1.98:8080/WebApp3/
ProxyPassReverseCookiePath /WebApp3 /WebApp3/
</VirtualHost>
stuck on configuring apache as proxy for applications running on tomcat on different pc. Everything seems working on the first application - WebApp1. But on the left ProxyPassReverseCookiePath is not working. ProxyPassReverseCookiePath works only on the first application. When accesing other applications a jsessionid is added to the url.
What I missed and how to fix on WebApp2 and WebApp3? Thanks
httpd-vhosts.con:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ProxyRequests off
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /WebApp1/ ajp://192.168.1.98:8009/WebApp1/
ProxyPassReverse /WebApp1/ ajp://192.168.1.98:8009/WebApp1/
ProxyPassReverse /WebApp1/ http://192.168.1.98:8080/WebApp1/
ProxyPassReverseCookiePath /WebApp1 /WebApp1/
ProxyPass /WebApp2/ ajp://192.168.1.98:8009/WebApp2/
ProxyPassReverse /WebApp2/ ajp://192.168.1.98:8009/WebApp2/
ProxyPassReverse /WebApp2/ http://192.168.1.98:8080/WebApp2/
ProxyPassReverseCookiePath /WebApp2 /WebApp2/
ProxyPass /WebApp3/ ajp://192.168.1.98:8009/WebApp3/
ProxyPassReverse /WebApp3/ ajp://192.168.1.98:8009/WebApp3/
ProxyPassReverse /WebApp3/ http://192.168.1.98:8080/WebApp3/
ProxyPassReverseCookiePath /WebApp3 /WebApp3/
</VirtualHost>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过更改 cookie 路径位置 dir 解决了这个问题:
Solved it by changing to cookie path location dir:
ajp 的优点之一是它将原始 URL 发送到 Web 应用程序。因此,通过 ProxyPassReverse 和 ProxyPassReverseCookiePath 进行的任何转换都是不必要的,因此您可以忽略这些指令。
与此无关,
ProxyPassReverseCookiePath
只是替换来自 Web 应用程序的 cookie 中的path
参数。正如您的情况,访问 Web 应用程序的路径与 Apache 提供该应用程序的路径相同,无需替换 cookie 路径中的任何内容。我可以想象你的原始代码不起作用的原因是它用
/WebApp1/
替换了/WebApp1
,所以你最终可能会得到/WebApp1 //
在 cookie 路径中,这可能会让浏览器感到困惑。 (我既不确定 Apache 在这种情况下是否进行转换,也不确定它是否会混淆浏览器。)我可以想象您发布的解决方案有效,因为 Apache 忽略了该指令,因为它包含无效路径。 (我也不确定 Apache 在这种情况下是否表现得如此。)One of the advantages of ajp is that it sends the original URL to the web application. So any transformations by
ProxyPassReverse
andProxyPassReverseCookiePath
are not necessary, so you can just leave those directives out.Unrelated to that,
ProxyPassReverseCookiePath
simply replaces thepath
parameter in the cookies that come from the web application. As in your case, the path that the web application is accessed under is the same as the path under which it is made available by Apache, it is not necessary to replace anything in the cookie path.I could imagine that the reason why your original code doesn’t work is because it replaces
/WebApp1
by/WebApp1/
, so you might end up with/WebApp1//
in the cookie path, which might confuse browsers. (I am neither sure whether Apache does the transformation in this case nor whether it confuses the browsers.) I could imagine that the solution that you posted works because Apache ignored the directive because it contains an invalid path. (I am also not sure whether that’s how Apache behaves in this case.)我遇到了同样的问题,以下配置解决了我的问题。
步骤 1:在虚拟主机上添加 ProxyPreserveHost On 属性。
步骤 2:为所有应用程序配置 ProxyPassReverseCookiePath,如下所示
希望这会有所帮助!
I had the same issue and following configuration fixed my problem.
step-1: Added
ProxyPreserveHost On
property on vhost.step-2: configured ProxyPassReverseCookiePath for all the application like below
Hope this will help!