Apache

Moderators: None (Apply to moderate this forum)
Number of threads: 150
Number of posts: 335

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can't figure out Apache VirtualHosts + Tomcat + ReverseProxy + Rewrite Posted by rave8151 on 15 Jul 2008 at 12:28 PM
Hi all, I have a problem that I can't seem to find info on anywhere!

CURRENT SETUP:
I'm running Apache 1.3 on Server_1 which directs all requests with JkMount to Server_2 which runs a home grown CMS application

('cmsapp') and a related application ('app1') on tomcat 5.

The CMS application services 20+ domains, and the Apache server uses VirtualHosts for each of them. e.g:

<VirtualHost 1.2.3.4:80>
	ServerAdmin webmaster@domain1.com
	DocumentRoot /usr/local/www/data/vhosts
	ServerName domain1.com
	ServerAlias www.domain1.com
	
	ErrorLog /usr/var/log/vhosts/www.domain1.com-error_log
	CustomLog /usr/var/log/vhosts/www.domain1.com-access_log combined
	
        JkMount /cmsapp/* worker1
	JkMount /app1/* worker1

	<Directory "/usr/local/www/data/vhosts">
		RewriteEngine On
		RewriteBase /	
		RewriteRule ^$ /cmsapp/homepage.html [L]
		RewriteRule ^([a-zA-Z0-9_-]{1,30})$ /cmsapp/$1.do.html [R]
	</Directory>
</VirtualHost>


The RewriteRules (as I understand them) allow us to direct to a different default starting page for each domain name, as

specified in the VirtualHost settings.

This all works fine and there have been no real problems with this setup for over 2 years.

PROBLEM:

An increase in the number of domains being managed by the CMS and the rise in traffic means our little tomcat server can't handle

it fast enough! I really want to upgrade to Apache 2.2 and get rid of the JkMount setup and implement a reverse proxy so I can

set up a cache for the Tomcat applications. This, I think, will alleviate the problems.

But try as I might I can't get the setup to work! Maybe my VirtualHost settings are wrong for Apache2.2, maybe I don't know

enough about Regex, but I think the problem is my lack of experience with mod_rewrite and mod_proxy.

Below are the best settings I have found so far for the domain shown above. This resolves requests for specific pages and

displays them properly, but the rewrite rules (which work for Apache 1.3) don't get executed. So instead of rewriting the request

for 'http://www.domain1.com' to the default homepage for that domain, it just goes to the Tomcat default homepage,

"$CATALINA_HOME/webapps/ROOT/index.jsp":

<VirtualHost 1.2.3.4:80>
	ServerAdmin webmaster@domain1.com
	DocumentRoot /usr/local/www/data/vhosts
	ServerName domain1.com
	ServerAlias www.domain1.com

        ErrorLog /usr/var/log/vhosts/www.domain1.com-error_log
	CustomLog /usr/var/log/vhosts/www.domain1.com-access_log combined

        ProxyRequests Off

        ProxyPass / http://1.2.3.111:8180/          #Tomcat Server
        ProxyPassReverse / http://1.2.3.111:8180/   

        <Directory "/usr/local/www/data/vhosts">
                RewriteEngine On
                RewriteBase /
                RewriteRule ^$ /cmsapp/homepage.html [L]
		RewriteRule ^([a-zA-Z0-9_-]{1,30})$ /cmsapp/$1.do.html[R]
        </Directory>
</VirtualHost>


I think the issue is something to do with the module order, but I can't figure out a solution. I read somewhere that one can

leave out the 'ProxyPass' directive and just use 'RewriteRule' to send requests through a compiled-in mod_proxy. I tried setting

that up but then I couldn't access any pages at all, with every request returning an HTTP 403 error message.

Does anyone know how I can get the old RewriteRule directives to work and fix this problem?
Report
Re: Can't figure out Apache VirtualHosts + Tomcat + ReverseProxy Posted by rave8151 on 16 Jul 2008 at 9:16 AM
For anyone experiencing similar problems, here are the VirtualHost settings that I used to fix my problems, provided by 'richardk' of

<VirtualHost 1.2.3.4:80>
   ServerName domain1.com
   ServerAlias www.domain1.com
   ServerAdmin webmaster@domain1.com

   ErrorLog  /usr/var/log/vhosts/www.domain1.com-error_log
   CustomLog /usr/var/log/vhosts/www.domain1.com-access_log combined

   RewriteEngine On

   RewriteRule ^/$ /cmsapp/homepage.html [PT,L]
   RewriteRule ^/([a-z0-9_-]{1,30})$ /cmsapp/$1.do.html [NC,R=301,L]

   ProxyRequests Off

   ProxyPass        / http://1.2.3.111:8180/ #Tomcat Server
   ProxyPassReverse / http://1.2.3.111:8180/
</VirtualHost>


: Hi all, I have a problem that I can't seem to find info on anywhere!
:
: CURRENT SETUP:
: I'm running Apache 1.3 on Server_1 which directs all requests with
: JkMount to Server_2 which runs a home grown CMS application
:
: ('cmsapp') and a related application ('app1') on tomcat 5.
:
: The CMS application services 20+ domains, and the Apache server uses
: VirtualHosts for each of them. e.g:
:
:
<VirtualHost 1.2.3.4:80>
: 	ServerAdmin webmaster@domain1.com
: 	DocumentRoot /usr/local/www/data/vhosts
: 	ServerName domain1.com
: 	ServerAlias www.domain1.com
: 	
: 	ErrorLog /usr/var/log/vhosts/www.domain1.com-error_log
: 	CustomLog /usr/var/log/vhosts/www.domain1.com-access_log combined
: 	
:         JkMount /cmsapp/* worker1
: 	JkMount /app1/* worker1
: 
: 	<Directory "/usr/local/www/data/vhosts">
: 		RewriteEngine On
: 		RewriteBase /	
: 		RewriteRule ^$ /cmsapp/homepage.html [L]
: 		RewriteRule ^([a-zA-Z0-9_-]{1,30})$ /cmsapp/$1.do.html [R]
: 	</Directory>
: </VirtualHost>

:
: The RewriteRules (as I understand them) allow us to direct to a
: different default starting page for each domain name, as
:
: specified in the VirtualHost settings.
:
: This all works fine and there have been no real problems with this
: setup for over 2 years.
:
: PROBLEM:
:
: An increase in the number of domains being managed by the CMS and
: the rise in traffic means our little tomcat server can't handle
:
: it fast enough! I really want to upgrade to Apache 2.2 and get rid
: of the JkMount setup and implement a reverse proxy so I can
:
: set up a cache for the Tomcat applications. This, I think, will
: alleviate the problems.
:
: But try as I might I can't get the setup to work! Maybe my
: VirtualHost settings are wrong for Apache2.2, maybe I don't know
:
: enough about Regex, but I think the problem is my lack of experience
: with mod_rewrite and mod_proxy.
:
: Below are the best settings I have found so far for the domain shown
: above. This resolves requests for specific pages and
:
: displays them properly, but the rewrite rules (which work for Apache
: 1.3) don't get executed. So instead of rewriting the request
:
: for 'http://www.domain1.com' to the default homepage for that
: domain, it just goes to the Tomcat default homepage,
:
: "$CATALINA_HOME/webapps/ROOT/index.jsp":
:
:
<VirtualHost 1.2.3.4:80>
: 	ServerAdmin webmaster@domain1.com
: 	DocumentRoot /usr/local/www/data/vhosts
: 	ServerName domain1.com
: 	ServerAlias www.domain1.com
: 
:         ErrorLog /usr/var/log/vhosts/www.domain1.com-error_log
: 	CustomLog /usr/var/log/vhosts/www.domain1.com-access_log combined
: 
:         ProxyRequests Off
: 
:         ProxyPass / http://1.2.3.111:8180/          #Tomcat Server
:         ProxyPassReverse / http://1.2.3.111:8180/   
: 
:         <Directory "/usr/local/www/data/vhosts">
:                 RewriteEngine On
:                 RewriteBase /
:                 RewriteRule ^$ /cmsapp/homepage.html [L]
: 		RewriteRule ^([a-zA-Z0-9_-]{1,30})$ /cmsapp/$1.do.html[R]
:         </Directory>
: </VirtualHost>
: 

:
: I think the issue is something to do with the module order, but I
: can't figure out a solution. I read somewhere that one can
:
: leave out the 'ProxyPass' directive and just use 'RewriteRule' to
: send requests through a compiled-in mod_proxy. I tried setting
:
: that up but then I couldn't access any pages at all, with every
: request returning an HTTP 403 error message.
:
: Does anyone know how I can get the old RewriteRule directives to
: work and fix this problem?





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.