简体   繁体   English

如何在一个Tomcat + Apache上部署多个Grails应用程序?

[英]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). 我已经阅读了StackOverflow上的几个问题并用Google搜索了几个小时,但我找不到一个完整而明确的答案来解决我在一个tomcat 5.5(使用Apache)上部署多个Grails应用程序的问题。 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. 使用Apache / Tomcat +虚拟主机部署多个grails应用程序的问题看起来很有希望但不起作用。 Maybe I need to do additional changes in Tomcat or Apache? 也许我需要在Tomcat或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) 在Tomcat的webapps目录中 ,我有两个war文件app1.war和app2.war,它们正在被Tomcat解压缩,我可以通过domain1.com/app1或domain1.com/app2访问(我删除了以前使用过的ROOT。战争和相关的webapps / ROOT /目录)

In the server.xml of Tomcat I have the following hosts: Tomcat的server.xml中,我有以下主机:

    <!-- 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 Apache中,我有以下虚拟主机: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? 我无法通过domain1.com和domain2.com直接访问这两个应用程序 - 我做错了什么?

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. 虽然它不使用mod_jk,但我选择了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. 我在Tomcat中的设置略有不同(我的版本是6 btw),我添加了多个连接器以及你拥有的Host声明。

Try the following - 尝试以下方法 -

In tomcat server.xml: 在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: 在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. 确保为Apache服务器启用mod_proxy。 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 我们在同一个tomcat下运行了两个Grails Web App

That was easy to do with tomcat 6 使用tomcat 6很容易

The difference I see with your server.xml is the name of the apps here what we have : 我在您的server.xml中看到的差异是我们拥有的应用程序名称:

<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 然后我们在tomcat root dir中有两个目录domain1.com和domain2.com在每个目录中,我们有一个webapps目录,它只为每个应用程序保存一个ROOT.war文件

Hope that helps 希望有所帮助

Cheers 干杯

Grooveek Grooveek

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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