How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?

Tomcat

Tomcat Problem Overview


How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?

Tomcat Solutions


Solution 1 - Tomcat

Several connectors are configured, and each connector has an optional "address" attribute where you can set the IP address.

  1. Edit tomcat/conf/server.xml.
  2. Specify a bind address for that connector:
    <Connector
    port="8080"
    protocol="HTTP/1.1"
    address="127.0.0.1"
    connectionTimeout="20000"
    redirectPort="8443"
    />
    

Solution 2 - Tomcat

it's well documented here:

https://cwiki.apache.org/confluence/display/TOMCAT/Connectors#Connectors-Q6

How do I bind to a specific ip address? - "Each Connector element allows an address property. See the HTTP Connector docs or the AJP Connector docs". And HTTP Connectors docs:

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

Standard Implementation -> 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."

Solution 3 - Tomcat

It may be worth mentioning that running tomcat as a non root user (which you should be doing) will prevent you from using a port below 1024 on *nix. If you want to use TC as a standalone server -- as its performance no longer requires it to be fronted by Apache or the like -- you'll want to bind to port 80 along with whatever IP address you're specifying.

You can do this by using IPTABLES to redirect port 80 to 8080.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScArcher2View Question on Stackoverflow
Solution 1 - TomcatScArcher2View Answer on Stackoverflow
Solution 2 - TomcatrnglbdView Answer on Stackoverflow
Solution 3 - TomcatHal50000View Answer on Stackoverflow