Search code examples
apachetomcatsession-cookies

Jsession in tomcat configuration


I have found that the value of my jsessionid cookies is value.*tomcatid* – e.g jsessionid=ahvrbsbbdhdhwh.tc12.

Where can I find the configuration of the Tomcat ID which is being concatenated with the jsessionid value?


Solution

  • The suffix you are seeing is called the jvmRoute and is configured in mod_jk's workers.properties file as either the name of the worker:

    worker.tc12.type=AJP13
    (etc)
    

    or by explicitly setting the name of the route property:

    worker.longname.type=AJP13
    worker.longname.route=tc12
    (etc)
    

    In Tomcat, the jvmRoute is set in conf/server.xml on the <Engine> element:

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tc12">
    

    If you want to change the route names, you will need to adjust both your mod_jk and Tomcat configurations to match each other.

    If you want to remove this suffix, then you will have to disable sticky sessions in mod_jk (sticky sessions are the default configuration) and also remove the jvmRoute attribute in your conf/server.xml:

    workers.properties
    ------------------
    worker.rc12.sticky_session = false
    

    and:

    conf/server.xml
    ---------------
    <Engine name="Catalina" defaultHost="localhost">
    

    This will disable sticky sessions which means that every request will go to an arbitrary Tomcat server.

    Even if you do not need sticky sessions (e.g. because you are using clustered Tomcats, mirgatable sessions, or you have a stateless web service), it might be a good idea to leave them enabled the the following reasons:

    1. Keeping defaults requires less configuration
    2. Sticky sessions can make clustered-session replication delays less problematic (e.g. you can use asynchronous session-replication since user requests will almost always go to the same node)

    Note that sessions are never sticky if your Tomcat nodes do not have any jvmRoute defined in the <Engine> component. So you can effectively disable session stickiness by removing your jvmRoute1s in your conf/server.xml files and no other re-configuration is necessary.