tomcat virtual directory installation and its configuration

Please reprint from the source: http://eksliang.iteye.com/blog/2097184

1.-------------------------------------------------------tomcat directory structure

  • config: store the configuration file of tomcat
  • temp : used to store temporary files after tomcat runs
  • work : When accessing the jsp file in the application for the first time, tomcat will first use the jsp file to generate the java file of the servlet, then compile it into .classes and store it in this directory
  • webapps : The directory where web applications are stored by default
  • temp
  • logs: the log directory where tomcat is stored
  • lib : the jar file that stores tomcat

2.-------------------------------------------- Several types of tomcat deployment Way

    Copy the application directly to {TOMCAT_HOME}/webapps and start tomcat

          Not much to say about this default deployment method

  1. The first type of virtual directory installation:

     Enter the {TOMCAT_HOME}/conf directory and modify server.xml

        Add in the <host/> node (if there are multiple projects, you can write multiple)

        <Context path="/hello" docBase="G:/display/test.war" debug="0" privileged="true"></Context>

       Parameter meaning:

  •  path: specifies the name of the web application to access
  • docBase: specifies the file path of the web application; if it is a war package, it must be suffixed
  • reloadable: If this property is set to true, the tomcat server will monitor the changes of the class files in the WEB-INF/classes and WEB-INF/lib directories when it is running. If it detects that the class files are updated, the server will automatically reload Load the web application, (set to true, then Tomcat will support hot deployment, will automatically detect changes in the /WEB-INF/lib and /WEB-INF/classes directories of the web, and automatically load new JSPs and Servlets. Change web without restarting Tomcat)

  2. The second virtual directory installation:

     Create a new xml in the {TOMCAT_HOME}/conf/catalina/localhost directory, the name can be whatever you want (create this directory if you don't have it, pay attention to capitalization)

     Add the following to the file:

     

<Context path="/hello" docBase="G:/display/test" debug="0" privileged="true"></Context>

 

      The meaning of the parameters is the same as the first one above

      Precautions:

            1. The name of the newly created xml file will be used as the name of the access application. The path here will be meaningless: it is recommended to change it to the following

             <Context docBase="G:/display/test" debug="0" privileged="true"></Context>

            2. If there are multiple applications, then configure multiple xml, remember that there can only be one Context in an xml

            3. If the application is started, if the xml file is added, the application will be dynamically loaded by tomcat

 

Virtual directory installation comparison:

            虚拟目录1和虚拟目录2最大的区别在于:第一种方式如果tomcat启动了,再加入Context,那么tomcat必须重新启动才能加载应用

             第二种种方式如果tomcat启动了,再加入xml文件,tomcat会在运行时动态加载应用

 

3.-------------------------------------------service.xml简单说明:

 注意如下:

  1. server.xml是不可动态重加载的资源,服务器一旦启动了以后,要修改这个文件,就得重启服务器才能重新加载
<Server port="8005" shutdown="SHUTDOWN">
port:指定一个端口,这个端口负责监听关闭Tomcat的请求

    

<Service name="Catalina">
    <!--Connector
	  - port:连接tomcat服务器的端口号,用来侦听客户端的请求
	  - protocol:协议,例如下面的protocol="HTTP/1.1" 就是http协议,说明此端口是用来侦听http协议的端口
	  - connectionTimeout:等待超时的时间数(以毫秒为单位)(default=”60000″)
	  - redirectPort:服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号,
	                 所有的Connector设定建议相同,这样就可以统一处理
	  - enableLookups:如果为true,则可以通过调用request.getRemoteHost()进行DNS查询来得到远程客户端  
                       的实际主机名;若为false则不进行DNS查询,而是返回其ip地址  
      - acceptCount:当所有可以使用的,处理请求的线程都被用光时,可以放到处理队列中的请求数,超过这个数  
                    的请求将不予处理,而返回Connection refused错误 
	  - maxThreads:设定在监听端口的线程的最大数目,这个值也决定了服务器可以同时响应客户请求的最大数目.默认值为200
	  - address:连接器所绑定的IP地址,当一台服务器存在多个ip地址时可以指定其中的需要绑定的一个,
				默认不设置该属性的值表示绑定当前服务器的所有ip地址

	  - minProcessors:服务器启动时创建的处理请求的线程数,每个请求由一个线程负责 
	  - maxProcessors:最多可以创建的处理请求的线程数  
	  - minSpareThreads:最小备用线程
	  - maxSpareThreads:最大备用线程
	  - maxPostSize:(default=2097152 即2MB) 最大允许 POST 上传的数据大小(单位为:字节),对于一般网站来说,
	                 比如有写评论写文章的网站,默认的2MB已经足够,不过如果网站带有图片甚至文件上传功能,则需要根据具体情况来定。
	  - debug:日志等级  
	  - disableUploadTimeout:禁用上传超时,主要用于大数据上传时 
	  - (像solr服务器通常是要中文的,必须配置)配置tomcat支持URL中文参数,只需添加Connector的URIEncoding参数即可,默认情况下该参数未被配置。
	    要支持URL参数支持中文,加上URIEncoding="UTF-8"就行了
	  -->
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
               redirectPort="8443" />
    
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    <!-- Engine
	  -   每个Service元素只能有一个Engine元素
	  -   name:对应$CATALINA_HOME/config/Catalina中的Catalina  
	  -   localhost:对应Host元素中的name属性,也就是和$CATALINA_HOME/config/Catalina/localhost中的localhost  
	  -->
    <Engine name="Catalina" defaultHost="localhost">
	  <!-- Realm
	    - 
	    -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
             <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                    resourceName="UserDatabase"/>
      </Realm>
      <!-- Host
        - appBase:就是设置web应用的存放位置,默认为webapps         
		- unpackWARs:如果为true,则tomcat会自动将WAR文件解压;否则不解压,直接从WAR文件中运行应用程序
        - autoDeploy:默认为true,表示如果有新的WEB应用放入appBase 并且Tomcat在运行的情况下,自动载入应用
        -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
		 <Context path="/solr"   docBase="D:/display/solr.war"   debug="0" privileged="true">  
                <Environment  name="solr/home"   
                              type="java.lang.String"   
                              value="D:/display/home" override="true"/>  
        </Context>  
        <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" />

      </Host>
    </Engine>
  </Service>

 

 

 

 

4.-------------------------------------------web.xml简单说明:

1.默认(欢迎)文件的设置,代码如下:

<welcome-file-list>
	<welcome-file>index.html</welcome-file>
	<welcome-file>index.htm</welcome-file>
	<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

 

 2.回话超时设置(单位/分钟)

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

 

 2.如下节点的说明

 <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>listings</param-name>
            <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    把false改为true,如果等于false访问http://IP:8080/search/update/,那么是不能访问webapp下面的目录结构:--默认为fasle

 

5.-------------------------------------------tomcat-users.xml简单说明

tomcat权限

 

<role rolename="manager"/>  
<role rolename="manager-gui"/>  
<role rolename="admin"/>  
<role rolename="admin-gui"/>  
<role rolename="manager-script"/>  
<role rolename="manager-jmx"/>  
<role rolename="manager-status"/>  
<user username="admin" password="admin123" roles="admin-gui,admin,manager-gui,manager,manager-script,manager-jmx,manager-status"/> 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326512868&siteId=291194637