tomcat server.xml ( 톰캣 서버 설정 )

server.xml을 통해서 tomcat이라는 web application server를 이해해보고자 한다. server.xml 설정에 목적이 있는 포스팅이 절대 아니다. 참고로 WAS는 J2EE 스펙(Servlet Container와 EJB Container의 기능)을 구현한 서버이지만, tomcat은 Servlet Container만 구현하고 EJB Container 기능은 없어서 WAS가 아니라는 사람도 있다. 그래서 '톰캣 == 서블릿 컨테이너'라고 알고있어도 좋다.

무엇이든 제대로 알려면 공식 문서를 보는 것이 신뢰성도 높고 마음도 편하다. 그래서 아래 아파치 톰캣 config doc을 참조하여 tomcat WAS(서블릿 컨테이너)의 구조를 파악하려고 한다.
https://tomcat.apache.org/tomcat-9.0-doc/config/index.html
  • Top Level Elements - <Server> is the root element of the entire configuration file, while <Service> represents a group of Connectors that is associated with an Engine.
  • Connectors - Represent the interface between external clients sending requests to (and receiving responses from) a particular Service.
  • Containers - Represent components whose function is to process incoming requests, and create the corresponding responses. An Engine handles all requests for a Service, a Host handles all requests for a particular virtual host, and a Context handles all requests for a specific web application.
  • Nested Components - Represent elements that can be nested inside the element for a Container. Some elements can be nested inside any Container, while others can only be nested inside a Context.
Server element represents the entire Catalina servlet container. Therefore, it must be the single outermost element in the conf/server.xml configuration file. Its attributes represent the characteristics of the servlet container as a whole.

Service element represents the combination of one or more Connector components that share a single Engine component for processing incoming requests. One or more Service elements may be nested inside a Server element.

The only components that may be nested inside a Service element are one or more Connector elements, followed by exactly one Engine element.

The HTTP Connector element represents a Connector component that supports the HTTP/1.1 protocol. It enables Catalina to function as a stand-alone web server, in addition to its ability to execute servlets and JSP pages. A particular instance of this component listens for connections on a specific TCP port number on the server. One or more such Connectors can be configured as part of a single Service, each forwarding to the associated Engine to perform request processing and create the response.

The description below uses the variable name $CATALINA_BASE to refer the base directory against which most relative paths are resolved. If you have not configured Tomcat for multiple instances by setting a CATALINA_BASE directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME, the directory into which you have installed Tomcat.
The Context element represents a web application, which is run within a particular virtual host.
The web application used to process each HTTP request is selected by Catalina based on matching the longest possible prefix of the Request URI against the context path of each defined Context. Once selected, that Context will select an appropriate servlet to process the incoming request, according to the servlet mappings defined by the web application deployment.
You may define as many Context elements as you wish. Each such Context MUST have a unique context name within a virtual host. The context path does not need to be unique. In addition, a Context must be present with a context path equal to a zero-length string. This Context becomes the default web application for this virtual host, and is used to process all requests that do not match any other Context's context path.

The Engine element represents the entire request processing machinery associated with a particular Catalina Service. It receives and processes all requests from one or more Connectors, and returns the completed response to the Connector for ultimate transmission back to the client.
Exactly one Engine element MUST be nested inside a Service element, following all of the corresponding Connector elements associated with this Service.

The Host element represents a virtual host, which is an association of a network name for a server (such as "www.mycompany.com") with the particular server on which Tomcat is running. For clients to be able to connect to a Tomcat server using its network name, this name must be registered in the Domain Name Service (DNS) server that manages the Internet domain you belong to - contact your Network Administrator for more information. 
One or more Host elements are nested inside an Engine element. Inside the Host element, you can nest Context elements for the web applications associated with this virtual host. Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.
Clients normally use host names to identify the server they wish to connect to. This host name is also included in the HTTP request headers. Tomcat extracts the host name from the HTTP headers and looks for a Host with a matching name. If no match is found, the request is routed to the default host. The name of the default host does not have to match a DNS name (although it can) since any request where the DNS name does not match the name of a Host element will be routed to the default host.
The description below uses the variable name $CATALINA_BASE to refer the base directory against which most relative paths are resolved. If you have not configured Tomcat for multiple instances by setting a CATALINA_BASE directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME, the directory into which you have installed Tomcat.


영어 울렁증이 있다면 아래 번역을 참고
  • Top Level Elements - <Server>는 전체 환경설정 파일의 root 요소이며, <Service>는 Engine과 연결된 Connectors 그룹이다.
  • Connectors - 특정 Service에 request를 보내고 response를 수신하는 외부의 클라이언트 간의 인터페이스를 대표한다.
  • Containers - 들어오는 request를 처리하고 response를 생성하는 기능이 있는 구성요소들(components)을 대표한다. Engine은 Service에 대한 모든 request를 처리하고, Host는 특정 virtual host에 대한 모든 request를 처리한다. 그리고 Context는 특정 web application에 대한 모든 request를 처리한다.
  • Nested Components - Container 내부요소 안에 중첩될 수 있는 요소들을 나타낸다. 일부 요소들은 Container 내부에 중첩될 수 있지만, 대부분의 다른 요소들은 Context 내부에만 중첩될 수 있다.

Server 요소는 Catalina servlet container 전체를 나타낸다. 그래서 conf/server.xml 구성 파일의 가장 바깥쪽 단일 요소여야 한다. 이것의 속성들은 servlet container 전체의 특성을 나타낸다.

Service 요소는 하나 또는 그 이상의 Connector components의 조합을 나타낸다. Connector components는 들어오는 request를 처리하는 하나의 Engine component를 공유한다. 하나 이상의 Service 요소는 Server 요소 내부에 중첩될 수 있다.

Service 요소 내부에 중첩될 수 있는 유일한 components는 하나 이상의 Connector 요소이고, 그 다음에 정확히 하나의 Engine 요소가 있다.

HTTP Connector 요소는 HTTP/1.1 protocol을 지원하는 Connector component를 나타낸다. Catalina는 servlet와 JAP pages를 실행할 수 있을 뿐만 아니라 독립 실행형 웹 서버(stand-alone web server)의 역할도 할 수 있다. 이 component의 특정 instance는 서버의 특정 TCP port number에 대한 연결을 수신한다. 이런 Connectors 중 하나 이상의 것들을 단일 Service의 부분으로 구성할 수 있으며, 각 Connectors는 연결된 Engine으로 전달해서 request를 처리하고 response를 생성할 수 있다.

아래 설명은 변수 이름 $ CATALINA_BASE를 사용하여 대부분의 상대 경로가 해석되는 기본 디렉토리를 나타냅니다. CATALINA_BASE 디렉토리를 설정하여 여러 인스턴스에 대해 Tomcat을 구성하지 않은 경우 $ CATALINA_BASE는 Tomcat을 설치 한 디렉토리인 $ CATALINA_HOME 값으로 설정됩니다.
Context 요소는 특정 virtual host 내에서 실행되는 하나의 web application을 나타낸다.
각 HTTP request를 처리하는 데 사용되는 web application은 각 정의된 Context의 context path 에 대해 Request URI의 가능한 가장 긴 prefix를 일치시키는 것을 기반으로 Catalina에 의해 선택된다.
일단 선택되면, 해당 Context는 web application deployment에 의해 정의된 servlet mapping에 따라 들어오는 request를 처리할 적절한 servlet을 선택한다.
원하는 만큼 많은 Context 요소를 정의할 수 있다. 이러한 각 Context는 virtual host 내에 유일한 context name을 가져야 한다. context path가 고유할 필요는 없다. 또한 Context는 길이가 0인 문자열과 동일한 context path가 있어야 합니다. (이것을 뜻함 -> path="") 이 Context는 이 virtual host를 위한 default web application이 되고, 다른 Context의 context path와 매칭되지 않는 모든 request를 처리하는 데 사용된다.

Engine 요소는 특정 Catalina Service와 연결된 전체 request 처리 기계를 나타낸다. 그것은 하나 이상의 Connector에서온 모든 request를 수신하여 처리하고 완성된 response를 Connector에 return하여 궁극적으로 Client에 전송하다.
Service 요소 내에는 정확히 하나의 Engine 요소가 중첩되어야 한다. 이 Service와 연결된 모든 Connector 요소 뒤에 위치시킨다.

Host 요소는 Tomcat이 실행중인 특정 server와 server의 network name (예를 들어 "www.mycompany.com")을 연결하는 virtual host를 나타낸다. Clients가 이 network name을 이용해서 Tomcat server에 연결하려면, 이 name이 속해있는 internet domain을 관리하는 Domain Name Service (DNS) server 에 등록되어 있어야 한다. 자세한 내용은 네트워크 관리자에 문의하십시오.
하나 이상의 Host 요소가 Engine 요소 내에 중첩되어 있습니다. Host 요소 내에 virtual host와 연결된 web application의 Context 요소를 중첩할 수 있다. 각 엔진과 연결된 호스트 중 정확히 하나가 해당 Engine의 defaultHost 속성과 일치하는 이름을 가져야 한다.
Client는 일반적으로 host name을 사용하여 연결하려는 server를 식별한다. 이 host name은 HTTP request header에도 포함된다. Tomcat은 HTTP header에서 host name을 추출하고 name이 일치하는 Host를 찾는다. 
일치하는 항목이 없으면 request는 default host로 라우팅된다. DNS name이 Host 요소의 name과 일치하지 않는 request는 default host로 라우트되므로 default host의 name은 DNS name과 일치할 필요는 없다(가능하지만).
아래 설명은 변수 이름 $ CATALINA_BASE를 사용하여 대부분의 상대 경로가 해석되는 기본 디렉토리를 나타냅니다. CATALINA_BASE 디렉토리를 설정하여 여러 인스턴스에 대해 Tomcat을 구성하지 않은 경우 $ CATALINA_BASE는 Tomcat을 설치 한 디렉토리 인 $ CATALINA_HOME 값으로 설정됩니다.


위의 내용을 참고하여 톰캣 아키텍처를 구성해보았다.


Tomcat WAS Architecture












<?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" />
  <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="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8009" protocol="AJP/1.3" 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="webapps"
            unpackWARs="true" autoDeploy="true">
        <Context docBase="C:\cansto\WEB\NewContext" path="/nc" reloadable="true">
          <Resource name="jdbc/myoracle" auth="Container"
           type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
           url="jdbc:oracle:thin:@127.0.0.1:1521:JAVA"
           username="scott" password="tiger" maxTotal="20" maxIdle="10"
           maxWaitMillis="-1"/>
        </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>
</Server>
cs






ㅇㄹㅇㄹ






















댓글

이 블로그의 인기 게시물

AWS RDS DB 인스턴스에 연결하기 (Oracle Database Instance)

Git resolving merge conflicts as Mark resolved (mark resolved 옵션으로 해결)