简体   繁体   中英

How to use different ports on single Tomcat instance which listens on a single port?

Using a single Tomcat instance, which listens on a single port, how can I host multiple websites under different hostnames and port numbers?

Example:

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?

Request 1:

GET /index.html HTTP/1.1
Host: www.sample.com

Request 2:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM