How to set a IP address to the tomcat? [closed]

2019-02-22 06:43发布

问题:

I have a Tomcat Server where a .war file is running.

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

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

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

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

How can I achieve this?

回答1:

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

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.html and http://wiki.apache.org/tomcat/FAQ/Connectors#Q6.



回答2:

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.



回答3:

Tomcat by default is listening on all IP addresses.

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

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.

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
    


回答4:

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?