I have a web application which I am setting up a shopping cart for; the application serves many different websites, each with it's own domain. Virtual Hosts are used to forward each domain to the Tomcat 6 server as well as set the path to that particular websites static resources; these static resources cannot be stored in the web application, and therefore are stored on the server and served through Apache.
开发者_如何学Cfirst I use JkMount on my context root, then do URL rewrite with [P, L] for taking the context path "mywebapp" out of the URL, so when someone goes to this application with the domain somedomain.com
the web application processes on somedomain.com/mywebapp/store/cart
but the browser sees somedomain.com/store/cart
. Until now this has been working very well; The problem is that every request is having it's session reset and I don't know why.
If I remove apache from the front end of serving the Session is not reset and works normally (as I expected). But I can't seem to set up my virtual host to forward to the application without losing sessions. I've read a lot about the problem but my competence is in JavaEE, and I have very little knowledge of Apache Web Server; so I'm not even sure how to begin researching the fix.
I've heard of something called ProxyPassing but I'm not sure what that means or how it works; most examples I've seen have changes to the Tomcat server.xml adding a domain, which I can't really do because domains (virtual hosts to match) get added dynamically and I can restart Apache, but can't be restarting the JavaEE application every time a new site is added.
Any ideas for fixing this, or getting to the root cause? Any alternative approaches?
UDPATE: I'm going to post my virtual host entry for one of the dynamic websites
<VirtualHost *:80>
ServerAdmin test@test.com
DocumentRoot "C:/wamp/www"
ServerName jawesome.com
ServerAlias www.jawesome.com
ErrorLog "logs/jawesome_com-error.log"
CustomLog "logs/jawesome_com-access.log" common
Alias /files/ "C:/static/1/uploaded_files/"
<Directory "C:/static/1/uploaded_files">
Options FollowSymLinks Indexes MultiViews
Order allow,deny
Allow from all
</Directory>
JkMount /webapp ajp13
JkMount /webapp/* ajp13
RewriteEngine on
#RewriteLogLevel 9
#RewriteLog "/usr/local/apache/logs/testrewrite.log"
RewriteCond %{REQUEST_URI} !^/(webapp/.*|files/.*)$
RewriteRule ^/(.*)$ /webapp/$1 [P,L]
</VirtualHost>
The Path
needs to be removed from the JSESSIONID cookie. One option would be to remove it in your Tomcat setup. Add emptySessionPath="true"
to your AJP Connector.
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" emptySessionPath="true"/>
The only gotcha is if you have other apps running on this same domain they would share this session id. But I don't see any in your config.
I'm on a team that is managing several java webapps each with their own authentication mechanisms. We have several apache servers load balanced and we're using ProxyPass to direct traffic to the backend webapps. So far, ProxyPass works well.
Here's an example that will proxy incoming requests to and from 'mywebapp' running on a tomcat server.
<VirtualHost *:80>
ServerName somedomain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /mywebapp http://tomcat-server:8080/mywebapp
ProxyPassReverse /mywebapp http://tomcat-server:8080/mywebapp
<Location />
Order allow,deny
Allow from all
</Location>
...
# can put rewrite rules here
...
</VirtualHost>
We also use rewrite rules and they work fine with proxypass definitions like this one.
Hope this helps, Good luck.
精彩评论