(原创)项目部署-Tomcat设置默认访问项目及项目重复加载问题处理
主要是通过配置<Tomcat安装目录>/conf/server.xml文件
步骤:
1、打开server.xml,在</Host>的上一行添加内容格式如下
<Context path="" reloadable="true" docBase="<项目名>"/>
如:
<Host name="www.abc.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> --> <Alias>www.123.org</Alias> <Alias>www.abc.com</Alias> <Context docBase="virgocloud" path="" reloadable="true"></Context> </Host> </Engine> |
另:如果想要只输入IP或域名就可以访问的话,那就把Tomcat的端口设置为80(但需确认此端口有没有其它程序占用),修改如下:
<Connector port="80" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
注:通过上面的设置有一个问题就是项目会重复加载两次.
原因分析
1.当为 Host 容器 设置了 appBase 属性时, Tomcat 会在启动时自动加载 appBase 指定目录下的所有合法工程;
2. 由于同时又通过 Context 的docBase 属性设置了Tomcat 默认工程, 所以,指定的 jkcm,virgocloud工程又会被加载一次
基于以上两点,造成了 jkcms,virgocloud工程的重复加载。
解决办法
1. 新建一个目录专门用于存放工程, 如:C:\virgocloud\software\apache-tomcat-7.0.57\deployproject
2. 将工程存放到以上目录下:即:C:\virgocloud\software\apache-tomcat-7.0.57\deployproject
3. 在 Context 容器中设置 docBase 属性, 如:
<Context path="" docBase="C:\virgocloud\software\apache-tomcat-7.0.57\deployproject\jkcms" />
<Host name="www.abc.com" appBase="webapps" unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> --> <Alias>www.123.org</Alias> <Alias>www.abc.com</Alias> <Context docBase="C:\virgocloud\software\apache-tomcat-7.0.57\deployproject\virgocloud" path=""reloadable="false"></Context> </Host> <Host name="cms.abc.com" appBase="webapps" unpackWARs="true" autoDeploy="true"xmlValidation="false" xmlNamespaceAware="false"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> --> <Context docBase="C:\virgocloud\software\apache-tomcat-7.0.57\deployproject\jkcms" path=""reloadable="false"></Context> </Host> |
至此问题解决,重启Tomcat服务器就可以通过不加项目名访问此项目.
注意:记得把webapps目录下的原项目删除
转载:请注明www.virgocloud.com或www.xujin.org
posted on 2015-02-01 16:45 Software_King 阅读(2553) 评论(0) 编辑 收藏 举报