Java 如何让 Tomcat 运行在 443 而不是它的默认端口 8080 上?

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

How to make Tomcat run on 443 instead of its default port 8080?

javatomcatweb-applicationsport

提问by Shivayan

We have a situation where we are required to run Tomcat and all its applications on port 443 instead of port 8080. Can anyone give a guidance on how this can be achieved? The process,its benefits and impacts.

我们有一种情况,我们需要在端口 443 而不是端口 8080 上运行 Tomcat 及其所有应用程序。谁能就如何实现这一点提供指导?过程,它的好处和影响。

回答by Abhishek Mishra

Tomcat_home/conf/server.xml

search for 
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

change 8080 to 443

回答by stripybadger

Look in conf/server.xml, there will be a <Connector>element containing the attribute port="8080"- you can change that to be whatever you want.

查看 conf/server.xml,将有一个<Connector>包含该属性的元素port="8080"- 您可以将其更改为您想要的任何内容。

However, if someone's asked to to run it on 443, I'd guess what they actually want is https? In which case see http://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.htmlfor how to set up ssl on tomcat.

但是,如果有人要求在 443 上运行它,我猜他们真正想要的是 https?在这种情况下,请参阅http://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html了解如何在 tomcat 上设置 ssl。

回答by Bartosz Mikulski

You can change Tomcat's port in the server.xml file (located in the conf directory). To change the port you have to modify the "port" attribute of the "connector" element.

您可以在 server.xml 文件(位于 conf 目录中)中更改 Tomcat 的端口。要更改端口,您必须修改“connector”元素的“port”属性。

If you want to run the Tomcat server on linux and you cannot run it as a privileged user you may use iptables to redirect the port 443 to 8080: iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080

如果你想在 linux 上运行 Tomcat 服务器并且你不能以特权用户身份运行它,你可以使用 iptables 将端口 443 重定向到 8080: iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8080