<Context path="" docBase="photo" debug="0" reloadable="true" /> <Context path="" docBase="项目路径" debug="0" reloadable="true" />修改端口、修改默认发布目录、多域名绑定
<Connector port="8080" protocol="HTTP/1.1"maxThreads="150" connectionTimeout="20000"
redirectPort="8443" /&gt;</code></pre>
<Connector port="8080" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" /&gt;</pre></code></pre>
<Connector port="80" protocol="HTTP/1.1"maxThreads="150" connectionTimeout="20000"
redirectPort="8443" /&gt;</code></pre>
<Connector port="80" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" /&gt;</pre></code></pre>
<Connector port="80" protocol="HTTP/1.1" maxThreads="150" connectionTimeout="20000"
redirectPort="8443" /> <Connector port="80" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" />
<Connector port="80" protocol="HTTP/1.1"maxThreads="150" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/&gt;</code></pre>
<Connector port="80" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/&gt;</pre></code></pre>
三、修改tomcat发布路径(默认路径:E:J2EEServerTomcat 6.0webappsROOT)
打开配置文件(我的在:E:J2EEServerTomcat 6.0confserver.xml),找到: <Engine name="Catalina" defaultHost="localhost"><Host name="localhost" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host>
</Engine> <Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host>
</Engine>在<host></host>标签之间添加上:path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;docBase是虚拟目录的路径,它默认的是$tomcat/webapps/ROOT目录,现在我在webapps目录下建了一个photo目录,让该目录作为我的默认目录。debug和reloadable一般都分别设置成0和true。这样,再访问服务器时就找$tomcat/webapps/photo下的页面了~~~~~三、多域名绑定打开配置文件(我的如下:D:Program FilesTomcatconfserver.xml),找到:
<Engine name="Catalina" defaultHost="localhost"><Host name="localhost" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt;
</Host>
</Engine> <Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt;
</Host>
</Engine>
方案一:多个工程在不同的目录下<Engine name="Catalina" defaultHost="pic.niejingyu.com"><Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/&gt;
<Host name="xixi.niejingyu.com" appBase="abcapps"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host> <Engine name="Catalina" defaultHost="pic.niejingyu.com">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/&gt;
<Host name="xixi.niejingyu.com" appBase="abcapps"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host>
<Host name="haha.niejingyu.com" appBase="D:Program FilesTomcattest"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host>
<Host name="lala.niejingyu.com" appBase="webapps"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt;
</Host>
</Engine> <Host name="haha.niejingyu.com" appBase="D:Program FilesTomcattest"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt;</code></pre>
</Host>
<Host name="lala.niejingyu.com" appBase="webapps"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt;
</Host>
</Engine>
测试在C:WINDOWSsystem32driversetc下的hosts文件中添加如下内容:
127.0.0.1 xixi.niejingyu.com
127.0.0.1 lala.niejingyu.com
127.0.0.1 haha.niejingyu.com
按照上面的配置:1. https://xixi.niejingyu.com 访问 ${tomcat} abcappsROOT 下的网站2. https://haha.niejingyu.com 访问 D:Program FilesTomcattestROOT 下的网站3. https://lala.niejingyu.com 访问 ${tomcat}webappsROOT 下的网站.Engine的dafaultHost:表示访问该tomcat默认进入的主机,注意一定不能是localhost,不然别人通过你的ip访问,就会默认进入tomcat的管理界面.Host 的 name:表示该主机绑定的域名,如果绑定localhost则可以通过在浏览器中输入localhost访问该Host.Host的 appBase:表示该主机绑定的文件存放路径,可以使用相对路径或绝对路径.方案二:多个工程在同一目录webapps下,即在不同的<host></host>里面配<Context>
<Engine name="Catalina" defaultHost="xixi.niejingyu.com"><Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/&gt;
<Host name="xixi.niejingyu.com" appBase="webapps"
unpackWARs="true" xmlValidation="false" xmlNamespaceAware="false"&gt; &lt;Context path="" docBase="test1" debug="0" reloadable="true" /&gt;</code></pre>
</Host>
<Host name="haha.niejingyu.com" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt; &lt;Context path="" docBase="test2" debug="0" reloadable="true" /&gt;</code></pre>
</Host>
<Host name="lala.niejingyu.com" appBase="webapps"
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false"&gt; &lt;Context path="" docBase="test3" debug="0" reloadable="true" /&gt;</code></pre>
</Host>