Java 如何给tomcat设置IP地址?

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

How to set a IP address to the tomcat?

javaweb-servicestomcatip-address

提问by silvia_aut

I have a Tomcat Server where a .warfile is running.

我有一个运行.war文件的 Tomcat 服务器。

I can run the .warfile when typing localhost:8080/..in the browser.

在浏览器中输入localhost:8080/..时,我可以运行.war文件。

But I have to reach this .war file over network. So I have a external IP with a domain name on it.

但是我必须通过网络访问这个 .war 文件。所以我有一个带有域名的外部IP。

And i should reach this .war file when typing xx.xxx.xxx.xxx:8080/..in browser.

我应该在浏览器中输入xx.xxx.xxx.xxx:8080/..时到达这个 .war 文件。

So this IP address should point to its localhost and further to the .warfile.

所以这个 IP 地址应该指向它的 localhost 并进一步指向.war文件。

How can I achieve this?

我怎样才能做到这一点?

回答by MariuszS

Tomcat by default is listening on all IP addresses.

默认情况下,Tomcat 正在侦听所有 IP 地址。

Check your firewall or router. This is network/routing problem, not related with Tomcat configuration.

检查您的防火墙或路由器。这是网络/路由问题,与 Tomcat 配置无关。

address: For servers with more than one IP address, this attribute specifies which address will be used for listening on the specified port. By default, this port will be used on all IP addresses associated with the server.

address:对于具有多个 IP 地址的服务器,此属性指定将用于侦听指定端口的地址。默认情况下,此端口将用于与服务器关联的所有 IP 地址。

http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

http://tomcat.apache.org/tomcat-7.0-doc/config/http.html



  1. Check if your IP is binded to tomcat server.

  2. Check if port is open

    telnet xx.xxx.xxx.xxx 8080
    
  1. 检查您的IP是否绑定到tomcat服务器。

  2. 检查端口是否打开

    telnet xx.xxx.xxx.xxx 8080
    

回答by Ted Bigham

If the external IP you have is assigned to WAN of your router, you'll have to set up port-forwarding or DMZ to your server using your routers admin panel. It's different for each brand, so you'll have to look it up for yours.

如果您拥有的外部 IP 已分配给路由器的 WAN,则必须使用路由器管理面板为服务器设置端口转发或 DMZ。每个品牌都不同,所以你必须为你自己寻找。

回答by Peter Svensson

Basically you configure your connector with the optional "address" attribute containing the ip address that you want to bind to.

基本上,您使用包含要绑定到的 IP 地址的可选“地址”属性配置连接器。

tomcat/conf/server.xml

tomcat/conf/server.xml

    <Connector 
        port="8080" 
        protocol="HTTP/1.1" 
        address="xxx.xxx.xxx.xxx"
        connectionTimeout="20000" 
        redirectPort="8443" 
      />

Information available at Tomcat homepage http://tomcat.apache.org/tomcat-7.0-doc/config/http.htmland http://wiki.apache.org/tomcat/FAQ/Connectors#Q6.

Tomcat 主页http://tomcat.apache.org/tomcat-7.0-doc/config/http.htmlhttp://wiki.apache.org/tomcat/FAQ/Connectors#Q6 上提供的信息

回答by Ashot Karakhanyan

Maybe it will be easier to change tomcat port from 8080 to 80. A lot of firewalls allows only port 80. You can see how to change it here: How to change the port of Tomcat from 8080 to 80?

也许把tomcat的端口从8080改成80会容易些。很多防火墙只允许80端口。你可以在这里看到如何改:如何将Tomcat的端口从8080改成80?