Using a single Tomcat instance, which listens on a single port, how can I host multiple websites under different hostnames and port numbers?
Let's say that the single tomcat instance is listening on a single port: At localhost:9090
.
How can I configure Tomcat and/or my webpages in order for both of the following requests (which are sent to localhost:9090
) to work?
GET /index.html HTTP/1.1
Host: www.sample.com
GET /index.html HTTP/1.1
Host: www.sample.com:120
Setup different connectors in conf/server.xml (don't choose ports below 1024):
....
<Connector port="80" connectionTimeout="20000" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="1234" connectionTimeout="20000" protocol="HTTP/1.1" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat8">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" autoDeploy="true"unpackWARs="true"></Host>
<Host name="www.sample.com" appBase="webapps-samplecom" autoDeploy="true"unpackWARs="true"></Host>
...
</Engine>
...
This will enable www.sample.com, www.sample.com:1234.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.