简体   繁体   中英

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.

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.

we have two Grails Web App running in production under the same tomcat

That was easy to do with tomcat 6

The difference I see with your server.xml is the name of the apps here what we have :

<Host name="www.domain1.com" appBase="[tomcat_root_dir]/www.domain1.com/webapps" unpackWARs="true"
    autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="www.domain2.com" appBase="[tomcat_root_dir]/www.domain2/webapps" unpackWARs="true"
    autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
</Host>

Then we have two directories domain1.com and domain2.com in tomcat root dir In each directory, we have a webapps dir which holds only a ROOT.war file for each app

Hope that helps

Cheers

Grooveek

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM