Richard210363
Richard210363

Reputation: 8406

Does Tomcat accept IPs?

I have a Tomcat app that is acting as a web server/gateway to Sun Systems Connect (which is itself the gateway to Systems Union Accounts that I suspect is the gateway to happiness).

I can access the app's login page via a browser as long as I use the machine name (or localhost when local). But neither the machines IP nor Localhost allows me to see the login page.

Sun tell me this is a 'feature' of Tomcat. Unfortunatly the accounts machines in development and in production have the same name (different domains) so I can't tell if I am running tests on the dev or live box. Short of changing the box names can I force Tomcat to accept IPs?

Upvotes: 0

Views: 158

Answers (3)

ZZ Coder
ZZ Coder

Reputation: 75496

Tomcat doesn't know anything about IPs. IP is just treated as hostname. You need to make sure the configuration allows the IP. You have a few options to achieve this.

If you add a defaultHost for the engine, any non-matching hostname or IP will use this virtual host. For example,

<Engine name="Standalone" defaultHost="example.com">

If you want more control, you can also add the IP as an alias, like

<Host appBase="webapps" name="example.com">
   <Alias>192.168.1.2</Alias>
</Host>

There are many other reasons that an IP may be rejected,

  1. SSL doesn't allow IP because certificate doesn't know anything about IP address.
  2. If you use virtual host on Apache or a front-end switch, it normally based on the decision on the hostname you use and it doesn't know how to route IP.
  3. You may have some security filter or rule to check Host headers in HTTP and specifically drops requests from unknown hosts.

Looking at logs may show you the exact cause.

Upvotes: 1

Todd Derscheid
Todd Derscheid

Reputation:

http://tomcat.apache.org/tomcat-4.1-doc/config/valve.html talks about a resolveHosts flag that forces a DNS lookup, also maybe with adjusting the pattern shown to one of the %A parameters you could list the IP address in the log.

Upvotes: 0

ire_and_curses
ire_and_curses

Reputation: 70220

It's been a while since I used Tomcat, but I thought by default you could call the web service via either name or IP address. I don't know if this will help, but you could try setting a virtual host for the IP address in server.xml, e.g. add a stanza something like

<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true">

but replacing "localhost" with your machine's IP address.

Upvotes: 0

Related Questions