Tomcat中配置多个网站,多个站点的方法

最近想要在tomcat中部署多个网站,但是不知道怎么配置,通过查找资料和摸索,发现要实现这一点其实还是很简单的。

如何利用Tomcat建立多个Web应用 呢?

重点就是:server.xml文件的配置

找到server.xml配置文件中的<Host>节点,通过增加host,来配置多个站点。

配置站点1


  
  1. <Host name="www.shishangshow.top" appBase="webapps"
  2. unpackWARs="true" autoDeploy="true">
  3. <Context path="" docBase="C:\yxy\tomcat\webapps\shishangshow" reloadable="true" >
  4. </Context>
  5. <!-- SingleSignOn valve, share authentication between web applications
  6. Documentation at: /docs/config/valve.html -->
  7. <!--
  8. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  9. -->
  10. <!-- Access log processes all example.
  11. Documentation at: /docs/config/valve.html
  12. Note: The pattern used is equivalent to using pattern="common" -->
  13. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  14. prefix="localhost_access_log" suffix=".txt"
  15. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  16. </Host>

配置站点2


  
  1. <Host name="www.yangxianyang.top" appBase="webapps"
  2. unpackWARs="true" autoDeploy="true">
  3. <Context path="" docBase="C:\yxy\tomcat\webapps\yangxianyang" reloadable="true" >
  4. </Context>
  5. <!-- SingleSignOn valve, share authentication between web applications
  6. Documentation at: /docs/config/valve.html -->
  7. <!--
  8. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  9. -->
  10. <!-- Access log processes all example.
  11. Documentation at: /docs/config/valve.html
  12. Note: The pattern used is equivalent to using pattern="common" -->
  13. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  14. prefix="localhost_access_log" suffix=".txt"
  15. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  16. </Host>

配置站点3

 


  
  1. <Host name="www.albertyy.com" appBase="webapps"
  2. unpackWARs="true" autoDeploy="true">
  3. <Context path="" docBase="C:\yxy\tomcat\webapps\yangxianyang" reloadable="true" >
  4. </Context>
  5. <!-- SingleSignOn valve, share authentication between web applications
  6. Documentation at: /docs/config/valve.html -->
  7. <!--
  8. <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  9. -->
  10. <!-- Access log processes all example.
  11. Documentation at: /docs/config/valve.html
  12. Note: The pattern used is equivalent to using pattern="common" -->
  13. <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
  14. prefix="localhost_access_log" suffix=".txt"
  15. pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  16. </Host>

就这样通过增加host就能配置多个站点了,还是挺简单。

文章来源: albertyang.blog.csdn.net,作者:Albert Yang,版权归原作者所有,如需转载,请联系作者。

原文链接:albertyang.blog.csdn.net/article/details/84667110

(完)