Hi. I’m having some real issues with configuring apache to do what I want it to do; I’m pretty novice when it comes to configuration.
Okay, so what I am basically trying to do is host instances of an application for separate clients behind a single domain name.
Say I have domain name mydomain.com. I have an application that runs on Tomcat with the root context of /myapp. I have 2 of these running, one on tomcat1, one on tomcat2.
What I want to do is type something like http://mydomain.com/client1/myapp, which will redirect to the appropriate Tomcat server as http://tomcat1/myapp.
After the session is established, I will use a unique JVM route (like is used for load balancing Tomcat through apache) so that http://mydomain.com/myapp requests for the rest of the session will get rewritten to http://tomcat1/myapp.
I can’t get this working.
Here is my current attempt. Any help would be much appreciated.
I left in my commented fragments so people can see other things I have tried.
Code:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias mydomain.com
RewriteEngine on
ProxyRequests off
ProxyStatus Full
ProxyPreserveHost On
<Location /server-status>
SetHandler server-status
</Location>
RewriteLog "C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\client1_rewrite.log"
RewriteLogLevel 9
#ProxyPassReverse /client1/ http://tomcat1:80/
#ProxyPassReverse /client1/ http://mydomain.com/
#ProxyPassReverse /client2/ http://tomcat2:80/
#RewriteCond %{HTTP_HOST} ^tomcat1$
#RewriteRule ^(.*)$ http://mydomain.com/$1 [N]
#RewriteRule ^/client1/(.{0}) http://tomcat1:80/myapp [P]
#RewriteRule ^/client1(.{0}) http://tomcat1:80/myapp [P]
#RewriteRule ^/client1(.*)$ http://tomcat1:80$1 [P]
#RewriteRule ^/client1/(.{0})$ http://mydomain.com/client1/myapp [N]
#RewriteRule ^/client1(.{0})$ http://mydomain.com/client1/myapp [N]
RewriteCond %{HTTP_REFERER} (/client1/) [OR]
RewriteCond %{HTTP_COOKIE} (.client12)
RewriteRule ^/(.*)$ client1/$1 [P]
#RewriteRule ^/(.*)$ http://tomcat1:80/$1 [P]
#RewriteRule ^/client2(.{0}) http://tomcat2:80/myapp [P]
#RewriteRule ^/client2/(.{0}) http://tomcat2:80/myapp [P]
#RewriteRule ^/client2(.*)$ http://tomcat2:80$1 [P]
RewriteCond %{HTTP_REFERER} (/client2/) [OR]
RewriteCond %{HTTP_COOKIE} (.client2)
RewriteRule ^/(.*)$ http://tomcat2:80/$1 [P]
<location /client1 >
ProxyPass http://tomcat1:80/
ProxyPassReverse http://tomcat1:80/
</location>
<location /client2/ >
ProxyPassReverse http://tomcat2:80/
</location>
</VirtualHost>