使用侦听单个端口的单个Tomcat实例,如何在不同的主机名和端口号下托管多个网站?
假设单个tomcat实例正在侦听单个端口:localhost:9090
。
我如何配置Tomcat和/或我的网页,以便以下以下请求(发送到localhost:9090
)工作?
GET /index.html HTTP/1.1
Host: www.sample.com
GET /index.html HTTP/1.1
Host: www.sample.com:120
答案 0 :(得分:0)
在conf / server.xml中设置不同的连接器(不要选择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>
...
这将启用www.sample.com,www.sample.com:1234。