Andrea Grimandi
Andrea Grimandi

Reputation: 641

Bind web applications to different addresses in Tomcat 7

Webapp named BOB must be reachable only through 192.168.3.56:8080

Tomcat is listening on two IP addresses on the same socket:

<Connector port="8080" 
 protocol="HTTP/1.1"
 address="192.168.3.56"/>

<Connector port="8080" 
 protocol="HTTP/1.1"
 address="192.168.3.57"/>

Despite the fact that I can't find any suitable parameter in the Apache Tomcat 7 Configuration Reference, can BOB be bindable to a specific <Connector>?

Upvotes: 1

Views: 98

Answers (1)

Andrea Grimandi
Andrea Grimandi

Reputation: 641

I've made an unexpected pretty solution searching deeply far and wide in Apache documentation.

Having two working connectors (ad I did), a way to bind a single webapp to one of them is to create a new Host in server.xml, as in my case:

<Host name="my.dns.app1.name"  appBase="webapp1-name" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" 
                directory="logs" 
                prefix="my_log_file." 
                suffix=".txt" 
                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

and then asking to our IT managers to register one new records on our DNS (or even in your file hosts on your OS)

192.168.3.56 -> my.dns.app1.name

Why using DNS? Because attribute name, as written in virtualhost on Apache documentation, expects a FQDN or something to resolve... maybe...

Now, every time the my.dns.app1.name:8080\BOB is invoked, BOB will answer!

PN: appBase="webapp1-name" must be created at the same level of the default webapp folder first and it will contain BOB as a normal web application. Every time my.dns.app1.name:8080\BOB is called, Tomcat will look inside the webapp1-name folder looking for BOB.

Upvotes: 1

Related Questions