LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 07-15-2008, 03:02 PM   #1
rave8151
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Rep: Reputation: 0
Can't figure out Apache VirtualHosts + Tomcat + ReverseProxy + RewriteRules


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:

Code:
<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":

Code:
<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?
 
Old 07-15-2008, 03:06 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
I'm not sure that you can put rewrite directives like that in a directory block. Try putting them directly in the virtualhost declaration, and see if their is a change in behavior.

Regards,

Alunduil

P.S. RewriteLog <logfile> may help too.
 
Old 07-15-2008, 04:05 PM   #3
rave8151
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the reply, alunduil. I tried what you suggested with putting the rewrite directives directly in the VirtualHost declaration, but it didn't work so I rechecked the documentation: you can use many rewrite directives in a directory or file block, and some directives will not work outside of them.

I tried adding the RewriteLog directive as you suggested, but it didn't give me anything useful. All I got from it was two entries for every URL I requested, e.g:

Code:
2.3.4.5 - - [15/Jul/2008:13:06:54 --0700] [www.domain1.com/sid#8181b20][rid#81fd058/initial] (2) init rewrite engine with requested uri /cmsapp/gobbledegook
2.3.4.5 - - [15/Jul/2008:13:06:54 --0700] [www.domain1.com/sid#8181b20][rid#81fd058/initial] (1) pass through /cmsapp/gobbledegook
This request for 'www.domain1.com/cmsapp/gobbledegook' returned the standard 404 page we use to my browser, but at the highest RewriteLogLevel (9), all I got were the above two entries in the rewrite log file
 
Old 07-16-2008, 12:15 PM   #4
rave8151
LQ Newbie
 
Registered: Jul 2008
Posts: 5

Original Poster
Rep: Reputation: 0
For anyone experiencing similar problems, here are the VirtualHost settings that I used to fix my problems, provided by 'richardk' of Mod_Rewrite Forums.

Code:
<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>

Last edited by rave8151; 07-16-2008 at 12:17 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically virtualhosts under Apache Chrizzieej Linux - Server 2 03-23-2008 04:17 AM
Help! Apache Reverseproxy & cache server maheshk78 Linux - General 0 11-16-2006 02:26 AM
Apache VirtualHosts and VSFTPd critical Linux - Software 3 09-14-2005 03:12 PM
Apache VirtualHosts Problem stratisphere Linux - Newbie 4 11-27-2004 01:20 AM
Apache RewriteRules? pk21 Linux - General 2 12-17-2003 08:43 AM


All times are GMT -5. The time now is 08:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration