Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy multiple Grails apps on one Tomcat + Apache?

I've read the several questions on StackOverflow and googled several hours but I can't find a complete and clear answer to my problem of deploying multiple Grails apps on one tomcat 5.5 (with Apache). Maybe someone can push me in the right direction or we can summarize a solution here.

The question Deploying multiple grails applications with Apache/Tomcat + Virtual Hosts looked promising but did not work. Maybe I need to do additional changes in Tomcat or Apache?

THE SITUATION:

In the webapps directory of Tomcat I have two war-files app1.war and app2.war which are getting unpacked by Tomcat and which I can access via domain1.com/app1 or domain1.com/app2 (I removed a previously used ROOT.war and the associated webapps/ROOT/ directory)

In the server.xml of Tomcat I have the following hosts:

    <!-- Logger shared by all Contexts related to this virtual host. -->
    <Logger className="org.apache.catalina.logger.FileLogger"
            directory="logs" prefix="localhost_" suffix=".log"
            timestamp="true"/>

    <!-- Allow symlinks for the tomcat-docs webapp. This is required in
         the Debian packages to make the Servlet/JSP API docs work. -->
     <Context path="/tomcat-docs" docBase="tomcat-docs" debug="0">
        <Resources className="org.apache.naming.resources.FileDirContext"
                   allowLinking="true" />
     </Context>

  </Host>

  <Host name="domain1.com" appBase="webapps/app1" unpackWARs="true" autoDeploy="true"></Host>
  <Host name="domain2.com" appBase="webapps/app2" unpackWARs="true" autoDeploy="true"></Host>

In Apache I have the following virtual hosts: ServerName app1.com

JkMount /* default

DocumentRoot /var/lib/tomcat5.5/webapps/app1
<directory /var/lib/tomcat5.5/webapps/app1>
    Options -Indexes
</directory>

LogLevel warn
ErrorLog  /var/www/app1/logs/error.log
CustomLog /var/www/app1/logs/access.log common

The Problem:

I cannot directly access the two applications via domain1.com and domain2.com - what am I doing wrong?

Many thanks in advance,

Joerg.

like image 345
Jörg Rech Avatar asked Apr 22 '11 02:04

Jörg Rech


People also ask

Can we deploy multiple applications in Tomcat?

You can of course have multiple apps in each directory if you need. Another option is to keep the default tomcat configuration and use another http server (apache, nginx, lighttpd,...) to map a port to the internal path of a tomcat application.

Can we deploy .NET application on Tomcat?

The Tomcat (Apache Tomcat) is Java exclusive, so it won't run anything . NET Core based. Refer this article: Host and deploy ASP.NET Core. Then, after deploy and host the API application, you can access the API method in another application, such as a Java application.


1 Answers

I struggled with this a while back and managed to get something that works ok. It doesn't use mod_jk though, I opted for mod_proxy. I also had a slightly different set up in Tomcat (mine is version 6 btw), where I added multiple connectors as well as the Host declarations you have.

Try the following -

In tomcat server.xml:

<!-- I opted for a shared thread pool so both apps share same resources - optional -->
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="250" minSpareThreads="40"/>


<Connector port="8081" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8444"
           executor="tomcatThreadPool"
           proxyName="www.domain1.com"
           proxyPort="80"/>
<Connector port="8082" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8445"
           executor="tomcatThreadPool"
           proxyName="www.domain2.com"
           proxyPort="80"/>

  <Host name="www.domain1.com" appBase="vhosts/domain1" unpackWARs="true"
        autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
            <Alias>domain1.com</Alias>
  </Host>
  <Host name="www.domain2.com" appBase="vhosts/domain2" unpackWARs="true"
        autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
            <Alias>domain2.com</Alias>
  </Host>

In Apache:

<VirtualHost *:80>
  ServerName www.domain1.com
  ServerAlias www.domain1.com

  ProxyRequests Off

  ErrorLog /var/log/apache2/error-domain1.log

  <Directory proxy:http://www.domain1.com:80>
        Order Allow,Deny
        Allow from all
  </Directory>

  <Proxy www.domain1.com:80>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://localhost:8081/
  ProxyPassReverse / http://localhost:8081/
  ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
  ServerName www.domain2.com
  ServerAlias www.domain2.com

  ProxyRequests Off

  ErrorLog /var/log/apache2/error-domain2.log

  <Directory proxy:http://www.domain2.com:80>
        Order Allow,Deny
        Allow from all
  </Directory>

  <Proxy www.domain2.com:80>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://localhost:8082/
  ProxyPassReverse / http://localhost:8082/
  ProxyPreserveHost On
</VirtualHost>

Make sure mod_proxy is enable for your Apache server. It was a while ago when I got this working, so I'm sure if everything is needed in that config - once I get it working I tend to forget stuff :)

Hope that helps, Chris.

like image 73
Chris Avatar answered Oct 25 '22 20:10

Chris