使用 mod_proxy 将连接从 80 上的 Apache 转发到 8080 上的 Tomcat 6

发布于 2024-12-19 05:24:43 字数 1459 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄与心 2024-12-26 05:24:43

如果没有特定原因使用 mod_proxy 来部署应用程序,那么 Tomcat Connectors / mod_jk 是一个更合适的解决方案。

请参阅

Tomcat 连接器指南

了解如何在 Apache 端设置连接器。请注意,JkMount /examples/*worker1 通过上下文挂载worker(以便示例中的所有内容都将由 Tomcat 处理),在您的配置中,您可能希望通过扩展挂载(甚至只是*),类似这样:

JkMount  /*.jsp worker1
JkMount  /*.do worker1
JkMount  /*.whatever worker1

这样所有匹配 *.jsp *.do 和 *.whatever 的内容都将由 Tomcat 处理,其余的由 apache 处理。 注意: JkMount 行需要位于您的定义内(在某些情况下)。

mod_jk 不使用 HTTP 连接 Tomcat,因此您可以禁用 HTTP 连接器(默认侦听 8080 的连接器)。您需要在 server.xml 中启用 AJP 连接器(不确定默认情况下是否启用),如下所示:

<Connector port="8009"
            enableLookups="false" redirectPort="8443" 
            protocol="AJP/1.3"/>

For Tomcat to recognize which application should respond to the Calls you need to执行主机配置并定义一个主机 与您匹配的 name站点名称。

然后定义一个 apache 虚拟主机,其 DocumentRoot 与 Tomcat 应用程序的 docBase 匹配,ServerName 与 Tomcat 的主机名匹配,如下所示:

httpd.conf :

<VirtualHost *:80>
DocumentRoot /var/www/yoursite.com
ServerName www.yoursite.com
</VirtualHost>

server.xml:

<Host name="www.yoursite.com" appBase="/var/www"
   unpackWARs="false" autoDeploy="false" deployOnStartup="false"
   xmlValidation="false" xmlNamespaceAware="false">
   <Context path="" docBase="/var/www/yoursite.com"/>

请注意,此设置不适用于 WAR 文件部署,而是用于解压(分解、提取)的 war 文件。 WAR 是一个 ZIP 存档,以防您不知道。

我很抱歉让它有点含糊,但它确实有效,而且这是在 Apache HTTPD 后面部署 Tomcat 应用程序的正确方法。

如果你用谷歌搜索它,你会找到带有演练的手册, 这个似乎是一个不错的。

If there is no specific reason to use mod_proxy to deploy your applications then Tomcat Connectors / mod_jk is a more suitable solution.

Please refer to

Tomcat connectors howto

for info how to setup connectors on Apache side. Notice that JkMount /examples/* worker1 mounts worker by context (so that everything in examples is going to be handled by Tomcat), in your configuration you would want to mount by extension (or even just *), something like this:

JkMount  /*.jsp worker1
JkMount  /*.do worker1
JkMount  /*.whatever worker1

so that everything matching *.jsp *.do and *.whatever would be handled by Tomcat, and the rest served by apache. Note: JkMount lines need to be inside your definition (in some cases).

mod_jk doesn't use HTTP to connect to Tomcat, so you can disable the HTTP connector (the one that listens to 8080 by default). You will need to enable AJP connector (not sure if it's enabled by default) with a line in server.xml something like this one:

<Connector port="8009"
            enableLookups="false" redirectPort="8443" 
            protocol="AJP/1.3"/>

For Tomcat to recognize which application should respond to the calls you would need to do Host configuration and define a Host with a name matching you site name.

Then you define an apache virtual host with DocumentRoot matching the docBase of Tomcat's application and ServerName matching the Tomcat's Host name, like this:

httpd.conf:

<VirtualHost *:80>
DocumentRoot /var/www/yoursite.com
ServerName www.yoursite.com
</VirtualHost>

server.xml:

<Host name="www.yoursite.com" appBase="/var/www"
   unpackWARs="false" autoDeploy="false" deployOnStartup="false"
   xmlValidation="false" xmlNamespaceAware="false">
   <Context path="" docBase="/var/www/yoursite.com"/>

Please note that this setup is not for a WAR file deployment, but rather for an unpacked (exploded, extracted) war file. WAR is a ZIP archive in case you didn't know.

I apologize for making it a bit vague, but it works, and this is the right way to deploy Tomcat applications behind Apache HTTPD.

If you google for it you will find manuals with walkthoughs, this one seems to be a good one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文