Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
01-11-2011, 08:55 AM
|
#1
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Rep:
|
Apache Proxy + Tomcat: Cannot maintain session data
Hi everyone!
Apache proxy with tomcat is working fine. The thing is that jsp sessions are not working through the proxy. How can I make it work?
Here's a sample of a virtualhost
Code:
<VirtualHost www.site1.domain.com>
ProxyRequests Off
ProxyPass / http://localhost:8080/tomcat/
ProxyPassReverse / http://localhost:8080/tomcat/
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
|
|
|
01-11-2011, 09:18 AM
|
#2
|
Member
Registered: Aug 2006
Location: Canada
Distribution: Debian, Slackware
Posts: 106
Rep:
|
Are you doing any sort of load balancing across multiple tomcat servers?
If so, something like this may help:
</Directory>
ProxyPass /balancer-manager !
ProxyPassReverse / ajp://192.168.1.164:8009
ProxyPassReverse / ajp://192.168.1.165:8009
ProxyPassReverse / ajp://192.168.1.166:8009
<Proxy balancer://myCluster>
BalancerMember ajp://192.168.1.164:8009 route=APPSERVER_NAME
BalancerMember ajp://192.168.1.165:8009 route=APPSERVER_NAME
BalancerMember ajp://192.168.1.166:8009 route=APPSERVER_NAME
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass balancer://myCluster/ stickysession=JSESSIONID
</Location>
The key here is the JSESSIONID, but this is mostly used for handling load balancing, to ensure that the client is always directed to the same
app server.
The next stage will be to put a capture tool such as wireshark on the line and see what is happening with the session id's as you test.
|
|
|
01-11-2011, 11:14 AM
|
#3
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Original Poster
Rep:
|
There's no load balancing. There is only one tomcat server.
It is still not working
|
|
|
01-11-2011, 01:59 PM
|
#4
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Original Poster
Rep:
|
I checked tomcat application manager and it shows that for each jsp page apache is requesting tomcat to create a new session.
But if I access the app directly (through tomcat http://localhost:8080/tomcat ) it works well, one session for all jsp pages.
If I change my virtualhost to:
Code:
<VirtualHost www.site1.domain.com>
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and access www.site1.domain.com/tomcat it works fine with 1 session for all pages.
But what I really want is to access www.site1.domain.com and "proxied" to http://localhost:8080/tomcat/ using sessions correctly.
|
|
|
01-11-2011, 02:35 PM
|
#5
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,201
|
Hi,
You can add "ProxyPreserveHost On" and if this isn't working you have 2 alternatives:
Edit the context path of the deployed application from "/tomcat" to ""
Or, you can use a rewrite rule, like:
Code:
<VirtualHost www.site1.domain.com>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ http://%{HTTP_HOST}/tomcat
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /tomcat http://localhost:8080/
ProxyPassReverse /tomcat http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Regards
Last edited by bathory; 01-16-2011 at 04:04 AM.
|
|
|
01-11-2011, 03:04 PM
|
#6
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Original Poster
Rep:
|
Using that virtualhost it didn't work (404 error). Here is what happened:
Code:
[Tue Jan 11 18:00:26 2011] [error] [client 10.101.15.17] File does not exist: /etc/apache2/htdocs
Don't no why it searched for /etc/apache2/htdocs since there's no virtualhost that references it.
Anyway, I guess I didn't make myself clear. It should work with this virtualhost:
Code:
<VirtualHost www.site1.domain.com>
ProxyRequests Off
ProxyPass / http://localhost:8080/tomcat/
ProxyPassReverse / http://localhost:8080/tomcat/
</VirtualHost>
Even if I add "ProxyPreserveHost On" to it, the problem remains.
Tried changing HTTP to AJP (with port 8009), sessions do not work properly either.
|
|
|
01-11-2011, 03:36 PM
|
#7
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,201
|
Hi,
Quote:
Don't no why it searched for /etc/apache2/htdocs since there's no virtualhost that references it.
|
Is that the apache DocumentRoot? If so, use the following in the vhost definition:
Code:
<VirtualHost *:80>
ServerName www.site1.domain.com
DocumentRoot /etc/apache2/htdocs
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ http://%{HTTP_HOST}/tomcat
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /tomcat http://localhost:8080/tomcat
ProxyPassReverse /tomcat http://localhost:8080/tomcat
</VirtualHost>
*** EDIT ***
Of course you need:
Code:
NameVirtualHost *:80
in httpd.conf
Last edited by bathory; 01-11-2011 at 03:44 PM.
|
|
|
01-12-2011, 07:01 AM
|
#8
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Original Poster
Rep:
|
All Virtualhosts are like this:
Code:
root@server:/etc/apache2/sites-enabled# cat *
NameVirtualHost 10.1.1.1
<VirtualHost 10.1.1.1>
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost www.site1.domain.com>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/site1/
ProxyPassReverse / http://localhost:8080/site1/
</VirtualHost>
<VirtualHost www.site2.domain.com>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^/$ http://%{HTTP_HOST}/site2
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
The real URL for site1 is http://localhost:8080/site1 . And for site2 is http://localhost:8080/site2. If I access those directly, sessions work fine.
With this configuration, fake URLs are www.site1.domain.com and www.site2.domain.com/site2. Only Site2 process sessions correctly. For Site1, tomcat is creating a session for each jsp page.
If I enter www.site2.domain.com it returns a 404 error. It seems rewrite entries aren't working. If I add "DocumentRoot /etc/apache2/htdocs" to site2 virtualhost configuration, the problem stays the same. Actually, that path doesn't even exist.
Site1 and Site2 have the same jsp pages for session testing.
There is just an empty index.html in /var/www/. So, when someone access http://10.1.1.1, it just shows a blank page.
|
|
|
01-12-2011, 08:34 AM
|
#9
|
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,201
|
Take care of the following things:
1.
Since you're using NameVirtualHost 10.1.1.1, you should use the same inside the <Virtualhost ...> tag. So every vhost should start like:
Code:
<VirtualHost 10.1.1.1>
ServerName www.site1.domain.com
...
2.
The rewrite stuff works. I've used it for similar configuration lots of times.
For mod_rewrite to work you need to enable the module. I guess you're using a debian based distro, so take a look here to see how it's done.
You also need to use
Code:
Options FollowSymLinks
inside the vhosts definition
3.
If /etc/apache2/htdocs is not your DocumentRoot, why did you get that error? You can use the actual docroot (/var/www)
4..
Since you have a session problem, the "ProxyPreserveHost On" is needed
So a complete vhost should look like this:
Try to setup a vhost as above and don't mix configurations
Regards
Last edited by bathory; 01-12-2011 at 08:36 AM.
|
|
|
01-14-2011, 12:28 PM
|
#10
|
Member
Registered: Aug 2007
Location: Salvador, Brazil
Distribution: Debian, Ubuntu
Posts: 185
Original Poster
Rep:
|
Finally, I got it.
The last issue was that tomcat wasn't aware of each virtualhost (domain).
Just added an entry into server.xml like this:
Code:
<Host name="www.site1.domain.com" appBase="/var/www/site1"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
and created a file /etc/tomcat6/Catalina/www.site1.domain.com/ROOT.xml with this content:
Code:
<Context path="/"
docBase="/var/www/site1"
antiResourceLocking="false" privileged="true" />
Virtualhost is like this:
Code:
<VirtualHost *:80>
ServerName site1.domain.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://site1.domain.com:8080/
ProxyPassReverse / http://site1.domain.com:8080/
</VirtualHost>
And now it works
Thanks for your support!
Regards,
|
|
|
All times are GMT -5. The time now is 10:34 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|