tomcat的跳转与日志
1.跳转的关键性配置; 2. 日志的配置
1.跳转的关键性配置
当用户访问http://www.a.com/test时,会跳转打开/var/www/html目录下的页面
关键性配置如下:
[root@web1 ~]# vim /usr/local/tomcat/conf/server.xml
...
<Host name="www.a.com" appBase="a" unpackWARS="true" autoDeploy="true">
<Context path="/test" docBase="/var/www/html/" /> //定义跳转目录/var/www/html/
</Host>
<Host name="www.b.com" appBase="b" unpackWARS="true" autoDeploy="true">
<Context path="" docBase="base" />
</Host>
...
[root@web1 ~]# echo "this is Test page" > /var/www/html/index.html //定义跳转目录的页面内容
[root@web1 ~]# /usr/local/tomcat/bin/shutdown.sh
[root@web1 ~]# /usr/local/tomcat/bin/startup.sh
[root@proxy ~]# firefox http://www.a.com:8080/test //查看页面是否为/var/www/html目录下的内容
2.日志的配置
- 为每个虚拟主机设置不同的日志文件
[root@web1 ~]# vim /usr/local/tomcat/conf/server.xml
...
<Host name="www.a.com" appBase="a" unpackWARS="true" autoDeploy="true">
<Context path="/test" docBase="/var/www/html/" />
#从默认localhost虚拟主机中把下面的Valve这段内容复制过来,适当修改下即可
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix=" a_access" suffix=".txt" //定义虚拟机www.a.com的日志文件, 前缀a_access后缀.txt
pattern="%h %l %u %t "%r" %s %b" />
</Host>
#从默认localhost虚拟主机中把下面的Valve这段内容复制过来,适当修改下即可
<Host name="www.b.com" appBase="b" unpackWARS="true" autoDeploy="true">
<Context path="" docBase="base" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix=" b_access" suffix=".txt" //定义虚拟机www.b.com的日志文件, 前缀b_access后缀.txt
pattern="%h %l %u %t "%r" %s %b" />
</Host>
...
# /usr/local/tomcat/bin/shutdown.sh
# /usr/local/tomcat/bin/startup.sh
# ls /usr/local/tomcat/logs/ //查看服务器日志文件
结束.