1

I currently have Apache 2.4 integrated with two tomcat servers in a load balancing configuration.

The webserver will take requests from the DNS request for two domain names, http://domain1.nl and http://domain2.nl

I wish to send requests for http(s)://domain1.nl/ to http(s)://domain1.nl/myapp1/login/login.do AND http(s)://domain2.nl/ to http(s)://domain2.nl/myapp2/

myapp1 and myapp2 are both running on both load balanced tomcat instances.

2 Answers2

0

Enable mod_rewrite and 'mod_proxy_http` on Apache.

<VirtualHost *:80>
  ServerName domain1.nl
  Rewriteengine on
  RewriteRule ^/$ http://domain1.nl/myapp1/login/login.do
  ProxyPass /myapp1 http://localhost:8080/myapp1
  ProxyPassReverse /myapp1 http://localhost:8080/myapp1
</VirtualHost>


<VirtualHost *:80>
  ServerName domain2.nl
  Rewriteengine on
  RewriteRule ^/$ http://domain2.nl/myapp2/
  ProxyPass /myapp2 http://localhost:8080/myapp2
  ProxyPassReverse /myapp1 http://localhost:8080/myapp2
</VirtualHost>

There is the copy/paste answer. But that will probably just lead to more questions because you don't get the fundamental understanding by copy/pasting verbatim.

Read all of Apache Virtual Host and Apache Rewrite Module documentation so you actually understand how it works so you can think with this.

To have those URL go through Apache to your backend Tomcat server, apply proxy directives as per the Apache Proxy documentation. Obviously, in the configuration above, localhost should be replaced with whatever host your Tomcat server is on.

ETL
  • 6,691
  • 1
  • 32
  • 49
0

Enable mod_rewrite and 'mod_proxy_http` on Apache.

Depending on apache version these mods may not exist (due to 'mod_'), try instead:

a2enmod rewrite
a2enmod proxy_http
service apache2 restart

And in your virtual host, this is what i use to redirect to tomcat and exclude php admin from forwarding:

    ProxyPreserveHost on
    ProxyRequests off
    ProxyPass /phpmyadmin ! 
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
Alpha2k
  • 121