Project deployment: Same IP, different port number, session failure

Source: Internet
Author: User
Tags tomcat server
background

I have two projects projecta, projectb,projecta in Tomcata, PROJECTB in TOMCATB, Tomcata, TOMCATB on a server.
The root path of the project is mapped and can be accessed without project name, as follows

http://ip1:7777/
http://ip1:8080/ Problem

Log in at 7777 First, then log in at 8080, and find that the 7777-port user will be kicked down, and then at 7777, you will be kicked down by 8080. speculate

Because the session state is implemented by the jsessionid stored in cookies, the first instinct is that Jessionid is overwritten. Then, I did the following test;

8080 Port Refresh
Because this is the first request, the server side returns cookies
Name is Jsessionid, domain name is localhost, path is/

7777 Port Refresh
Request 7777, incredibly will be sent with a 8080-port cookie, 8080 of the SessionID in 7777 Tomcat must not find, so returned the new SessionID (name is jsessionid, domain name is localhost, path is/) , and then cover the SessionID of the 8080 generated.

We found the cause of the problem, because the SessionID of the two projects, the name, domain, path are the same, causing SessionID to be overwritten, resulting in the session invalidation, which also concluded that cookies are not differentiated port. Solve

There are three solutions for distinguishing paths, domain names, and names based on cookies.

Setting a domain name is different, such as
http://projectA.com:7777/
http://projectB.com:8080/

Set the path differently, set the project name, no longer map the root path, such as
Http://ip1:7777/projectA
Http://ip1:8080/projectB

Set key differently
Configure Sessioncookiename in Tomcat's Server.xml, as long as two different can
Tomcat Server.xml Context Configuration


Original address: Click on the Open link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.