I have a bunch of problems with JSESSIONID cookie in different scenarios. I've already read a lot information, but it feels crazy, when things do not work as expected.
Long story short, I have a web server behind proxy server (nginx). Proxy handles requests with HTTPS (and redirects HTTP to HTTPS), also proxy has LDAP authorization (does not matter but anyway).
On the web server machine apache proxy is configured, that redirects from 443(https) to 80 port. Web server is Tomcat, it is configured in server.xml to use secure cookies (connector settings).
To summarize
[browser] -----> [nginx proxy] -----> [tomcat app server]
Now problems:
When open app from intranet (requests go directly to app server without nginx proxy), cookies are not cached at all. Developer tools show, that response contains JSESSIONID cookie, but new requests do not use it and app breaks.
Key moments: server returns secure cookie
When open app from internet (requests go through nginx proxy), cookies are cached. Application works fine. But cookies are not secure, though they might be (because tomcat is configured and we run through HTTPS).
So, I want to understand why cookies are not cached in first case and why cookies are not secure in second case.
Update
I removed
<session-config>
<cookie-config>
<secure>true</secure>
</cookie-config>
</session-config>
from web.xml (it was intended to make all cookies secure, I found it somewhere in web)
After that, problem 1 was solved (cookies are cached now) and problem 2 is solved too (cookies are secure). Honestly, I don't understand this magic and want to hear some expert explanation.