如何从 Apache 重定向到 Tomcat?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/603765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:20:59  来源:igfitidea点击:

How do I redirect from Apache to Tomcat?

apacheurltomcatports

提问by Alan

I'm working on my first Java site. I'm running Apache Tomcat on port 8080, and Apache HTTPD on port 80. The current URL that I can access the site at is (for example) 123.4.5.6:8080. I want to removethe port number from the URL before I point the domain at the new IP.

我正在我的第一个 Java 站点上工作。我在端口 8080 上运行 Apache Tomcat,在端口 80 上运行 Apache HTTPD。我可以访问该站点的当前 URL 是(例如)123.4.5.6:8080。我想在域指向新 IP 之前从 URL 中删除端口号。

At the moment I am only using Apache for phpmyadmin, however I plan on using it for CGI scripts and other stuff once I figure out mod_jketc... So I don't want to change Tomcat's port to 80 and turn off Apache.

目前我只将 Apache 用于 phpmyadmin,但是我计划在我弄清楚后将它用于 CGI 脚本和其他东西mod_jk……所以我不想将 Tomcat 的端口更改为 80 并关闭 Apache。

I hope this makes sense.

我希望这是有道理的。

回答by kgiannakakis

The correct way to do things is to leave Apache at 80 and Tomcat at 8080 and use a plug in (preferably mod_proxy) to proxy Tomcat from Apache. mod_proxy would only take you 10 minutes to set up.

正确的做法是让Apache在80,Tomcat在8080,并使用插件(最好是mod_proxy)从Apache代理Tomcat。mod_proxy 只需 10 分钟即可完成设置。

This how-tois very simple to follow.

此操作方法非常易于遵循。

回答by Eddie

The usual way this is done, as you already mentioned, is to use mod_jkfrom Apache HTTPD to forward that content that you want to be processed by Tomcat.

正如您已经提到的,通常的做法是使用mod_jkApache HTTPD 转发您希望由 Tomcat 处理的内容。

There is a Quick HowToat tomcat.apache.org. You need to do the following:

在 tomcat.apache.org 上有一个Quick HowTo。您需要执行以下操作:

  • Copy mod_jk.sointo the appropriate modules directory for Apache HTTPD.
  • Create a configuration file workers.properties
  • In Apache HTTPD's httpd.conf, add a section to configure mod_jk.
  • Ensure that Tomcat is configured to accept the mod_jkprotocol, which is usually on port 8009.
  • 复制mod_jk.so到 Apache HTTPD 的相应模块目录中。
  • 创建配置文件 workers.properties
  • 在 Apache HTTPD 中httpd.conf,添加一个部分来配置mod_jk.
  • 确保 Tomcat 已配置为接受该mod_jk协议,该协议通常在端口 8009 上。

The lines in httpd.confwith JkMount:

在该行httpd.confJkMount

JkMount  /examples/* worker1

tell Apache HTTPD which requests are to be forwarded to Tomcat.

告诉 Apache HTTPD 哪些请求将被转发到 Tomcat。

回答by gareth_bowles

Both the helpful answers above are good, but I much prefer mod_proxyover mod_jk. There's no extra installation to do for mod_proxy, unlike mod_jk, and the setup is much easier. mod_jkgives you more control over detailed tuning of Tomcat parameters, but if you just want a simple redirect from Apache to Tomcat, mod_proxyis the way to go.

上面这两种有用的答案都不错,但我更喜欢mod_proxymod_jk。与 不同mod_jk,mod_proxy 无需额外安装,而且设置要容易得多。 mod_jk使您可以更好地控制 Tomcat 参数的详细调整,但如果您只想要从 Apache 到 Tomcat 的简单重定向,这mod_proxy是要走的路。

回答by bodrin

If you want static content to be served by Apache instead of Tomcat you should use mod_jk : http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html

如果您希望 Apache 而不是 Tomcat 提供静态内容,您应该使用 mod_jk :http: //tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html

And what about SSL - if we want Apache to handle HTTPS, because it is faster then java/Tomcat?

那么 SSL 呢——如果我们希望 Apache 处理 HTTPS,因为它比 java/Tomcat 更快?

回答by Haid

you should configure your tomcat using this link. for tomcat 7 http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html

您应该使用此链接配置您的 tomcat。对于 tomcat 7 http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html