tomcat部署多个项目,公网通过域名解析访问,不同的网站

1.首先需要有多个域名,同时指向一个IP地址。

例如:域名:www.bbb.com, www.aaa.com等等。

解析到一个公网IP地址:210.34.120.110.

2.需要对tomcat下的conf下的"server.xml"进行配置

  1. <Server port="8005" shutdown="SHUTDOWN">
  2. <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  3. <Listener className="org.apache.catalina.core.JasperListener" />
  4. <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  5. <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  6. <GlobalNamingResources>
  7. <Resource name="UserDatabase" auth="Container"
  8. type="org.apache.catalina.UserDatabase"
  9. description="User database that can be updated and saved"
  10. factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  11. pathname="conf/tomcat-users.xml" />
  12. </GlobalNamingResources>
  13. <Service name="Catalina">
  14. <Connector port="8080" protocol="HTTP/1.1"
  15. connectionTimeout="20000"
  16. redirectPort="8443" URIEncoding="gbk" />
  17. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  18. <!--以下配置是关键-->
  19. <Engine name="Catalina" defaultHost="localhost">
  20. <!--默认通过localhost转发-->
  21. <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  22. resourceName="UserDatabase"/>
  23. <!--以下是自带的转发-->
  24. <Host name="localhost" appBase="webapps"
  25. unpackWARs="true" autoDeploy="true"
  26. xmlValidation="false" xmlNamespaceAware="false">
  27. </Host>
  28. <!-- 在tomcat安装目录下新建文件夹aaa 与webapp同级,然后在该目录下新建Root,项目内容可放在这个位置 -->
  29. <Host name="www.aaa.com" appBase="aaa"
  30. unpackWARs="true" autoDeploy="true"
  31. xmlValidation="false" xmlNamespaceAware="false">
  32. </Host>
  33. <!-- 同上,在tomcat安装目录下新建文件夹bbb与webapp同级 , 然后在该目录下新建Root,项目内容可放在这个位置 -->
  34. <Host name="www.bbb.com" appBase="bbb"
  35. unpackWARs="true" autoDeploy="true"
  36. xmlValidation="false" xmlNamespaceAware="false">
  37. </Host>
  38. </Engine>
  39. </Service>
  40. </Server>

这样,就可以访问多个项目,通过不同的域名进行。

附:如果进行本地测试。则需加如下配置:

C:\Windows\System32\drivers\etc\hosts(Vista系统下路径,其他操作系统可能不一样)

  1. # Copyright (c) 1993-2006 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. # 102.54.94.97 rhino.acme.com # source server
  17. # 38.25.63.10 x.acme.com # x client host
  18. 127.0.0.1 www.aaa.com
  19. 127.0.0.1 www.bbb.com
  20. 127.0.0.1 localhost


» 本文链接:https://blog.apires.cn/archives/218.html
» 转载请注明来源:Java地带  » 《tomcat部署多个项目,公网通过域名解析访问,不同的网站》

» 本文章为Java地带整理创作,欢迎转载!转载请注明本文地址,谢谢!
» 部分内容收集整理自网络,如有侵权请联系我删除!

» 订阅本站:https://blog.apires.cn/feed/

标签: Tomcat

添加新评论