1 修改配置文件
vim /tomcat7/conf/server.xml
将<Engine name="Catalina" defaultHost="localhost"> 改为<Engine name="Catalina" defaultHost="forbiden">
默认的请求会找去forbiden的host配置进行访问,不配置name为forbiden的host也可以。
推荐:改成forbiden就可以,不需要配置。
如果要配置如下:
<Host name="forbiden" appBase="notexists"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false"></Host>
它会去找notexists的项目,当然这里可以随便配置一个不存在的项目的路径。
2 指定正常的域名访问
<Host name="www.tangboxiang.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Host name="www.tangboxiang.com" appBase="webapps"
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 "%r" %s %b" />
</Host>
3 拓展
可以添加一个通过IP访问,不添加不可通过IP访问
<Host name="119.xx.xx.xxx" appBase="webapps"
unpackWARs="true" autoDeploy="true"