Tomcat虚拟主机搭建Web站点

来源:互联网 发布:知乎提问没人浏览 编辑:程序博客网 时间:2024/05/17 23:31

Tomcat配置完成虚拟主机,可以在虚拟主机中搭建Web站点

创建Web站点

首先,在D盘中,创建一个newhost目录,将开发的好的chapter02应用复制到newhost目录中,然后,将welcome.html页面中的内容,修改为”这是newhost目录中的welcome.html文件”

这里写图片描述

配置server.xml文件

在server.xml文件中,增加一个元素,将该元素
name属性设置为:itcast
appBase属性设置为:d:\newhost
具体代码

<Host name="itcast"  appBase="d:\newhost"unpackWARs="true" autoDeploy="true"><!-- 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 Note: The pattern used is equivalent to using pattern="common" --><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"   prefix="localhost_access_log." suffix=".txt"   pattern="%h %l %u %t &quot;%r&quot; %s %b" /></Host>

这里写图片描述

配置虚拟主机与IP

在Windows系统的hosts文件中,配置虚拟主机与IP地址的映射关系
具体代码
127.0.0.1 itcast

这里写图片描述

注意

前面不要加#号,#号表示注释
如果,加上#号,将无法访问itcast虚拟主机

重启Tomcat服务器

在浏览器的地址栏中,输入地址
http://itcast:8080/chapter02/welcome.html
显示结果

这里写图片描述