7

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?

silvia_aut
  • 1,481
  • 6
  • 19
  • 33
  • so you want to access the app in your local network or via internet – SpringLearner Jan 23 '14 at 09:23
  • Port 8080 is open on firewall? – MariuszS Jan 23 '14 at 09:23
  • possible duplicate of [How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?](http://stackoverflow.com/questions/18617/how-do-you-configure-tomcat-to-bind-to-a-single-ip-address-localhost-instead-o) – MariuszS Jan 23 '14 at 09:24
  • i want to have access via internet and for this i have generated an external ip address. – silvia_aut Jan 23 '14 at 09:25
  • @MariuszS How to see if port is open? – silvia_aut Jan 23 '14 at 09:26
  • Assuming tomcat is listening on 8080 by default, try `telnet xx.xxx.xxx.xxx 8080`, – MariuszS Jan 23 '14 at 09:27
  • 1
    Wait, where do you have this public IP? Are you sure that you have it assigned to you server? If not, then you must enable port forwarding on your router or dmz etc – Mr. P Jan 23 '14 at 09:27
  • http://wiki.apache.org/tomcat/FAQ/Connectors#Q6 – MariuszS Jan 23 '14 at 09:28
  • 1
    Sory for myself-respond but, only if your server has public IP assigned, you can consider firewall blocking or tomcat bind address changing. – Mr. P Jan 23 '14 at 09:29
  • @Pisek ok i will check this, maybe something is wrong. – silvia_aut Jan 23 '14 at 09:30
  • @Pisek can you please tell me how to access tomcat but using external ip? – SpringLearner Jan 23 '14 at 09:56
  • 1
    @JqueryLearner, fisrt of all check if your server does have a external IP assigned. If yes, it is highly probable you are able to access it already as Tomcat is listening on all IPs possible. If, however, you do not have a public IP, but your router has, you have to enable port forwarding on it to your server (something like: incoming 8080 to 192.168.1.2 port 8080 depending on your LAN ip of the server) – Mr. P Jan 23 '14 at 10:14

4 Answers4

8

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.

Peter Svensson
  • 6,105
  • 1
  • 31
  • 31
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.

Mr. P
  • 1,387
  • 1
  • 11
  • 25
Ted Bigham
  • 4,237
  • 1
  • 26
  • 31
0

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
    
MariuszS
  • 30,646
  • 12
  • 114
  • 155
0

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?

Community
  • 1
  • 1
Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
  • if i do this, i cant start the tomcat anymore – silvia_aut Jan 23 '14 at 09:33
  • Probably port 80 is already taken. – MariuszS Jan 23 '14 at 09:34
  • Yes maybe already taken, but it's possible to release it, stopping the application which uses that port, if it is not so relevant. – Ashot Karakhanyan Jan 23 '14 at 09:38
  • 1
    Btw, the question was about *And i should reach this .war file when typing xx.xxx.xxx.xxx:8080/..*, so why 80? – MariuszS Jan 23 '14 at 09:52
  • 1
    @AshotKarakhanyan, if you do not provide a answer but a proposal, consider adding a comment – Mr. P Jan 23 '14 at 10:10
  • 1
    @Pisak, my answer is possible solution, because I had such situation, when only port 80 is allowed. Yes, it was be better to add comment but for it I needed 50 reputation(I don't have it yet), so I added a answer which possibly can help. So it was better to not answer anyway? – Ashot Karakhanyan Jan 25 '14 at 07:11