JSessionID 在 Apache Web 服务器上不持久

JSessionID is not persistent on Apache web server

下面是我的 httpd.conf 配置。我有 tomcat 服务器作为后端服务器,我使用 apache 网络服务器作为我的 tomcat 服务器的代理。

以下配置适用于不需要会话的所有网页。

进一步调查后,我观察到 JSESSIONID 在每个 Web 请求上都在变化,这意味着,当请求和响应通过 Apache http 服务器进行时,该 ID 不会保留。

请注意,当我尝试将 tomcat 服务器直接暴露给 Web 时,JSESSIONID 是持久的并且按预期工作。但是,出于安全要求,我们需要使用 tomcat 服务器作为后端内部服务器。

所以我不确定为什么 apache http 服务器不喜欢正确处理 JSESSIONID。请求您的帮助,并指导我配置中缺少的内容。

注意:我们不需要任何负载平衡器设置,所以我目前不考虑 mod_proxy_balancer 模块。

<VirtualHost *:443>
ServerName www.external.com
ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
         AddOutputFilterByType SUBSTITUTE text/html
    ProxyPreserveHost off
    ProxyPass / http://localhost:8080/internal/
    ProxyPassReverse / http://localhost:8080/internal/    
    Substitute "s|http://localhost:8080/internal|https://www.external.com|i"                
    SSLProtocol all
    SSLEngine on     
    SSLCertificateFile C:/keys/site/external_cert.cer       
    SSLCertificateKeyFile C:/keys/site/www_internal_private.p12.pri.pem
    SSLCertificateChainFile C:/keys/site/Intermediate_CA.cer
</VirtualHost>

Apache 网络服务器是 Apache 2.4,tomcat 引擎是 Tomcat 8.5

关注 serverfault answer 添加 Set-Cookie Header:

In the end I just had to add the following line to my VirtualHost configuration, which changes all cookie paths from /WEBAPP_NAME to / (root):

Header edit Set-Cookie "^(.*; Path=)/WEBAPP_NAME/?(.*)" /