- 编辑tomcat配置文件server.xml
- 在Engine块下添加host配置
host常用属性说明
name:访问域名
appBase:静态资源位置
unpackWARs:是否解压war包
autoDeploy:是否支持自动部署
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="www"
unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
</Service>
</Server>
例如:
- 在tomcat根目录创建www/static文件夹
- 在www下创建static文件夹
- 将index.html文件上传至static下
- 访问地址:http://localhost:8080/static/index.html