Apache proxy cookies works only with the first app

2019-08-11 17:09发布

问题:

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>

回答1:

Solved it by changing to cookie path location dir:

ProxyPassReverseCookiePath /WebApp1/ http://192.168.1.98:8080/WebApp1/


回答2:

One of the advantages of ajp is that it sends the original URL to the web application. So any transformations by ProxyPassReverse and ProxyPassReverseCookiePath are not necessary, so you can just leave those directives out.

Unrelated to that, ProxyPassReverseCookiePath simply replaces the path 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.)



回答3:

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

   ProxyPassReverseCookiePath /   /WebApp1

   ProxyPassReverseCookiePath /   /WebApp2

   ProxyPassReverseCookiePath /   /WebApp3

Hope this will help!