Java 端口 80 上的 Tomcat Webapp

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16326707/
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-08-16 06:19:22  来源:igfitidea点击:

Tomcat Webapp on port 80

javatomcattomcat6

提问by eLRuLL

I have a webapp on my tomcat server like this:

我的 tomcat 服务器上有一个 webapp,如下所示:

mydomain.com:8080/mywebapp

mydomain.com:8080/mywebapp

Then I connect to my webapp, and it is working correctly, but what I want is to see my webapp like this:

然后我连接到我的 webapp,它工作正常,但我想要的是像这样看到我的 webapp:

mydomain.com

mydomain.com

So I don't want only tomcat on port 80, I don't want to access my webapp through its name, I want to connect directly using my domain URI.

所以我不想只在端口 80 上使用 tomcat,我不想通过它的名称访问我的 webapp,我想直接使用我的域 URI 进行连接。

How can I do this? I want this to work with Linux (Ubuntu 12.04 LTS) and Windows servers.

我怎样才能做到这一点?我希望它适用于 Linux (Ubuntu 12.04 LTS) 和 Windows 服务器。

采纳答案by NilsH

There are several ways to achieve this, but the most common way to solve it is to run Apache as a reverse proxy in front of it. You can find some details here. This will work on both Linux and Windows. For Linux, you can also use authbindto allow Tomcat to bind to port 80. Just changing the port to 80in your server.xmlwill not work in Linux, since it would require you to start Tomcat as root, which is not a very good idea.

有几种方法可以实现这一点,但最常见的解决方法是在其前面运行 Apache 作为反向代理。您可以在此处找到一些详细信息。这将适用于 Linux 和 Windows。对于Linux,您也可以使用authbind允许Tomcat 绑定到端口 80。仅将端口更改为80inserver.xml在 Linux 中将不起作用,因为它需要您将 Tomcat 启动为root,这不是一个好主意。

Also, to have your webapp at /, you can deploy your war file as ROOT.war.

此外,为了让您的 webapp 位于/,您可以将您的 war 文件部署为ROOT.war.

回答by NullPointerException

You need to set apache webserver and configure it to use tomcat.

您需要设置 apache 网络服务器并将其配置为使用 tomcat。

You need to use mod_jkin order to configure apache webserver to communicate with tomcat.

您需要使用mod_jk才能配置 apache webserver 与 tomcat 通信。

Use this linkto set up the mod_jk.

使用此链接设置mod_jk.

回答by ilikeorangutans

Running any application on a privileged port (those below 1024) requires special privileges. If you do this, you should ensure your instance is properly hardened.

在特权端口(低于 1024 的端口)上运行任何应用程序都需要特殊权限。如果你这样做,你应该确保你的实例得到了适当的强化

To configure the port tomcat listens on you have to modify the HTTP connector in conf/server.xml (server reference documentation):

要配置 tomcat 侦听端口,您必须修改 conf/server.xml(服务器参考文档)中的 HTTP 连接器:

<Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

To change the context path of an app, you can rename the war file. To deploy it at the root, rename your war file to ROOT.war. Or you can add a META-INF/context.xml in which you can specify the desired context path (context reference docs):

要更改应用程序的上下文路径,您可以重命名 war 文件。要将其部署到根目录,请将您的 war 文件重命名为 ROOT.war。或者您可以添加一个 META-INF/context.xml,您可以在其中指定所需的上下文路径(上下文参考文档):

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" />