Tomcat去掉项目工程名访问

一、需求

去掉项目工程名称访问,比如 http://ganhuopu.run:2001/blog ,要去掉blog这个工程名,变成 http://ganhuopu.run:2001可以访问。

二、解决方案

这时候就要修改tomcat的配置!!!配置文件的路径是tomcat/conf/server.xml,具体配置内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<Server port="16001" 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" />


  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">
    <Connector port="2001" protocol="org.apache.coyote.http11.Http11NioProtocol"
               connectionTimeout="20000"
               maxThreads="4000"
               executor="tomcatThreadPool"
               URIEncoding="UTF-8" 
               maxPostSize="-1"
               maxParameterCount="-1"
               redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps1"
            unpackWARs="true" autoDeploy="true">
        <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" />
	<Context path="" docBase="D:\tomcat\webapps\blog" debug="0"/>
      </Host>
    </Engine>
  </Service>
</Server>


三、重点提示:

1、path为空代表当前路径,docBase代表工程的具体路径,有时候docBase="blog"也行,但是会出现莫名其妙的问题,建议写成全路径的,切记!!!
<Context path="" docBase="D:\tomcat\webapps\blog" debug="0"/>
2、工程所在的目录不能和appBase的目录相同:如果blog的工程在webapps文件夹内,则appBase就不能配置成webapps,否者项目会启动两次,切记!!!

image.png

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×