Michael

写写代码,说说人生

您好,我是Michael,欢迎来到我的个人家园。
代码搬运工,目前就职于XX证券,努力修行中。


H5 / Java / Objc / Swift / Vue / RN

Tomcat设置不需要项目名便可访问项目(直接用域名或者ip和端口访问)

实际生产中往往访问web项目要求直接使用ip+端口或者使用域名便可直接访问项目,不加/项目名称。配置起来其实是非常简单的。

tomcat\conf目录下找到server.xml,在<Host></Host>配置里面添加一行配置。

<Context docBase="D:\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\webapps\waGong" path="/" reloadable="true" />

docBase是项目的物理路径(项目不必非要放在tomcat下面,可以放在磁盘的任意位置,只要此处物理路径配置正确,tomcat能找到项目位置就可以),path是虚拟路径。将path设置成/便可不需要项目名称便可访问项目。

<Host></Host>里面可以设置多个项目,每个项目一行Context设置。

配置完成后打开浏览器访问下http://localhost:80效果如下。

tomcat-port-04

项目上线的时候,将Hostname属性从默认的localhost修改为域名。项目便可直接通过域名访问。

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
  <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>
  <Service name="Catalina">
 
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
    <Engine defaultHost="localhost" name="Catalina">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
 
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>
 
         <Context docBase="D:\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\wtpwebapps\weike" path="/weike" reloadable="true" source="org.eclipse.jst.jee.server:weike"/>
 
         <Context docBase="D:\apache-tomcat-8.0.36-windows-x64\apache-tomcat-8.0.36\webapps\waGong" path="/" reloadable="true" />
      </Host>
    </Engine>
  </Service>
</Server>
最近的文章

Android 8.0 的填坑(透明的activity崩溃)

透明的activity 不能继续使用 java.lang.RuntimeException:Unable to start activity ComponentInfo{net.maipeijian.xiaobihuan/com.etop.EtoVinActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation原因是:sdk27版本使用 if targetSd...…

Android开发继续阅读
更早的文章

Tomcat多项目共用80端口,不同域名映射不同项目

废话不多说,直接进入主题。准备工作: jdk1.8(配好环境变量) tomcat8在tomcat中添加项目在webapps中添加3个项目,这3个都是很简单的项目,只有index.html和web.xml。index.html只有一个h1标签,里面写了web1、web2和web3用于区分3个项目。index.html<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8">...…

Tomcat继续阅读