简体   繁体   English

Apache Tomcat 配置 - 一台 Apache 服务器和多个 Tomcat 站点

[英]Apache Tomcat Configuration - One Apache Server and Multiple Tomcat Sites


I'm facing one issue while configuring apache web server for multiple tomcat sites.我在为多个 tomcat 站点配置 apache web 服务器时遇到一个问题。
Here's my requirement :这是我的要求:
1. Apache webserver - Single Instance 1. Apache 网络服务器 - 单实例
2. Same application(WebApps) across 3 different multiple tomcat instances 2. 跨 3 个不同的多个 tomcat 实例的相同应用程序(WebApps)
The front end server and app server all hosted on single server(Solaris)前端服务器和应用服务器都托管在单个服务器上(Solaris)

When I access Apache server with a particular site name, It should pick up the apps only from that tomcat site当我使用特定站点名称访问 Apache 服务器时,它应该仅从该 tomcat 站点中获取应用程序

I tried various options while going through different sites on google but unfortunately no option resolved this issue as of now..我在 google 上浏览不同网站时尝试了各种选项,但不幸的是,到目前为止,没有任何选项可以解决这个问题。

My Current Modification in vhost conf file and workers.properties (Apache Server) and server.xml on app server are as below.我在 vhost conf 文件和应用服务器上的 workers.properties(Apache 服务器)和 server.xml 中的当前修改如下。

<VirtualHost x.x.x.x:80>

  ServerAdmin webmaster@xxx.com
  DocumentRoot /opt/htdocs/test-1.xxx.com/docs

  ServerName x.x.x.x
  ServerAlias test1-1.xxx.com

:
:
:
</VirtualHost>

<VirtualHost x.x.x.x:80>

  ServerAdmin webmaster@xxx.com
  DocumentRoot /opt/htdocs/test-2.xxx.com/docs

  ServerName x.x.x.x
  ServerAlias test1-2.xxx.com

:
:
:
</VirtualHost>
<VirtualHost x.x.x.x:80>
  ServerAdmin webmaster@xxx.com
  DocumentRoot /opt/htdocs/test-3.xxx.com/docs
  ServerName x.x.x.x
  ServerAlias test1-3.xxx.com

:
:
:
</VirtualHost>

Worker.properties Worker.properties

worker.list=tomcat1,tomcat2,tomcat3

worker.tomcat1.type=ajp13
worker.tomcat1.host=test1-1.xxx.com
worker.tomcat1.port=8009



worker.tomcat2.type=ajp13
worker.tomcat2.host=test1-2.xxx.com
worker.tomcat2.port=48009


worker.tomcat3.type=ajp13
worker.tomcat3.host=test1-3.xxx.com
worker.tomcat3.port=58009

Server.xml - The port numbers are different for each instance as mentioned in workers.properties.Here what I've modified on each tomcat instance in server.xml in terms of host name. Server.xml - 正如workers.properties 中提到的,每个实例的端口号都不同。这里我在server.xml 中的每个tomcat 实例上修改了主机名。 Please assume that all the port no.s are different for all 3 tomcat instances请假设所有 3 个 tomcat 实例的所有端口号都不同

tomcat-1 tomcat-1

<Engine name="Catalina" defaultHost="test1-1.com" jvmRoute="tomcat1">
<Host name="test1-1.com"  appBase="webapps"  
            unpackWARs="true" autoDeploy="true">

<Engine name="Catalina" defaultHost="test1-2.com" jvmRoute="tomcat2">
<Host name="test1-2.com"  appBase="webapps"  
            unpackWARs="true" autoDeploy="true">

<Engine name="Catalina" defaultHost="test1-3.com" jvmRoute="tomcat3">
<Host name="test1-3.com"  appBase="webapps"  
            unpackWARs="true" autoDeploy="true">

The problem is that, every time when I launch any tomcat site, every time it's picking up the webapp from first tomcat server ie test1-1.com问题是,每次当我启动任何 tomcat 站点时,每次它从第一个 tomcat 服务器(即 test1-1.com)获取 webapp 时

eg If I open, http://test1- 2 /home/index then though the site is opening but it's picking up the webapps directory from "test1-1.com" site..例如,如果我打开, HTTP:// test1-然后2 /首页/指数虽然该网站是开放,但它是从“test1-1.com”现场拿起webapps目录下..

My requirement is that - When I open http://test1- 2 /home/index, it should pick up the webapps which is hosted on tomcat site-2 ie test1-2.com我的要求是-当我打开HTTP:// test1- 2 /首页/指数,它应该拿起这是对托管网站的tomcat-2即test1-2.com的web应用

Please let me know, what's wrong I'm doing here .. Feel free to ask me if you need any more info请告诉我,我在这里做什么错了.. 如果您需要更多信息,请随时问我

Unfortunately I can not use mod_jk module as all my webapps directory structure are same across all 3 tomcat instances - so pattern matching is not possible不幸的是,我不能使用 mod_jk 模块,因为我所有的 webapps 目录结构在所有 3 个 tomcat 实例中都是相同的 - 所以模式匹配是不可能的

Thanks in advance提前致谢

Finally I was able to complete this assignment with loads of changes across multiple servers.最后,我能够在多台服务器上进行大量更改来完成这项任务。 Actually above configuration was right only except 'NameVirtualHost' tag was missing in vhost config file and some configuration on CMS from where it was fetching contents..实际上,上面的配置仅是正确的,只是 vhost 配置文件中缺少“NameVirtualHost”标签,并且 CMS 上的一些配置是从那里获取内容的。

--Cheers-- - 干杯 -

Your virtualhost config is missing the JKMount option to tell apache which worker should be used to serve the content: https://tomcat.apache.org/tomcat-3.3-doc/mod_jk-howto.html您的虚拟主机配置缺少 JKMount 选项来告诉 apache 应该使用哪个 worker 来提供内容: https ://tomcat.apache.org/tomcat-3.3-doc/mod_jk-howto.html

You can also use apache ProxyPass to achieve almost the same result.您也可以使用 apache ProxyPass 来实现几乎相同的结果。 In your situation, jkmount is a better option because if you have multiple tomcat serving the same application, it's easier to create a configuration to load balance traffic and guarantee HA.在您的情况下,jkmount 是更好的选择,因为如果您有多个 tomcat 为同一应用程序提供服务,则更容易创建配置来负载平衡流量并保证 HA。

About the apache config I suggest you the following:关于 apache 配置,我建议您执行以下操作:

  1. change <VirtualHost xxxx:80> to <VirtualHost *:80> so apache is listening on any interface, port 80. (Tell apache to work on nameBased VirtualHost instead of ipBased)<VirtualHost xxxx:80>更改为<VirtualHost *:80>以便 apache 监听任何接口,端口 80。(告诉 apache 使用 nameBased VirtualHost 而不是 ipBased)
  2. I see your ServerName xxxx is the same in every virtualhost: this does not work.我看到您的ServerName xxxx在每个虚拟主机中都相同:这不起作用。 ServerName and ServerAlias should be unique in your configuration or, if i recall correctly, the first one read by apache will match and the others will be ignored. ServerName 和 ServerAlias 在您的配置中应该是唯一的,或者,如果我没记错的话,apache 读取的第一个将匹配,而其他的将被忽略。

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

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