๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
TOMCAT

[Tomcat] ํ†ฐ์บฃ(Tomcat) ๊ตฌ์กฐ ๋ฐ ํ”„๋กœ์„ธ์Šค (web.xml, server.xml)

by w1z 2024. 2. 29.

๐Ÿ“Tomcat ํฐ 3๊ฐ€์ง€ ๊ตฌ์„ฑ

Coyote : Tomcat TCP ํ”„๋กœํ† ์ฝœ ์ง€์›
Catalina : Java Servlet์„ ํ˜ธ์ŠคํŒ… ํ•ด์ค€๋‹ค.
Jasper : JSP ํŽ˜์ด์ง€ ์š”์ฒญ ์ฒ˜๋ฆฌ Servlet

 

๐Ÿ“ํ†ฐ์บฃ ๋™์ž‘ ๊ตฌ์กฐ

Tomcat Server๊ฐ€ ๊ทธ ๋ฐ‘์— Service ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค (๊ทธ ํ•˜์œ„์—๋Š” Engine, Connector(ํ˜ธ์ถœ ํฌํŠธ), Host, Context(URI Mapping) ๋“ฑ์ด ์กด์žฌ)

HTTP ํ†ต์‹  ์š”์ฒญ → ํ˜ธ์ถœ ํฌํŠธ์— ํ•ด๋‹นํ•˜๋Š” Connector ์—ฐ๊ฒฐ → Service → Engine → Host → Context(๊ธฐ๋ณธ์ ์œผ๋กœ webapps์— ์žˆ๋Š” ๊ณณ ์ฐธ์กฐํ•ด ํ”„๋กœ์ ํŠธ URI Mapping → ํ”„๋กœ์ ํŠธ ๋‚ด web.xml ์ฝ๊ธฐ → ํ”„๋กœ์ ํŠธ ๋‚ด web.xml ๊ธฐ๋ฐ˜์œผ๋กœ ํ”„๋กœ์ ํŠธ URI ๋งคํ•‘

 

 

 

ํ•˜๋‚˜์˜ Server์—๋Š” ์—ฌ๋Ÿฌ๊ฐœ Service๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค.
ํ•˜๋‚˜์˜ Service์—๋Š” 1๊ฐœ์˜ Engine๊ณผ ์—ฌ๋Ÿฌ๊ฐœ์˜ Connector๋กœ ๊ตฌ์„ฑ
ํ•˜๋‚˜์˜ Engine์—๋Š” ์—ฌ๋Ÿฌ๊ฐœ Host ์กด์žฌํ•  ์ˆ˜ ์žˆ๋‹ค.
ํ•˜๋‚˜์˜ Host์—๋Š” ์—ฌ๋Ÿฌ๊ฐœ Context๊ฐ€ ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

Tomcat Server → Engine(Connector๋กœ ํ†ตํ•ด ์ „๋‹ฌ) → Host → Context 

[Tomcat์—์„œ๋Š” server.xml์— ์ ํ˜€์žˆ๋Š” ๋‚ด์šฉ์„ ๊ฐ€์ง€๊ณ  ๊ฐ์ฒด๋ฅผ ๋งŒ๋“œ๋Š” ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— Connector์— ํฌํŠธ๋ฒˆํ˜ธ๋ฅผ ์ ์–ด๋‘๋ฉด ์–ด๋–ค Service๋ฅผ ์ด์šฉํ• ์ง€ ๋ฐฉํ–ฅ์„ ์•Œ๋ ค์ค€๋‹ค]

 

๐Ÿ“Server

port : Shutdown ๋ช…๋ น์„ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” TCP/IP ์ฃผ์†Œ

<Server port="8005" shutdown="SHUTDOWN">

 

๐Ÿ“Service

Serivce์˜ ์œ ์ผํ•œ ์ด๋ฆ„์œผ๋กœ Log๋ฅผ ๋‚จ๊ธธ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค (Catalina.out)

<Service name="Catalina">

 

 

๐Ÿ“Connector

 

ํŠน์ • TCP port์—์„œ request๋“ค์„ listenํ•ด engine์œผ๋กœ ๋ณด๋‚ด์ค€๋‹ค.

  • port
    • ๋ฆฌ์Šจํ•  ํฌํŠธ
  • protocol
    • TCP/IP ๋ฐฉ์‹ 
  • HTTP/1.1
    • ๊ธฐ๋ณธ์ ์œผ๋กœ Connection๋‹น ํ•˜๋‚˜์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌ ํ•˜๋„๋ก ์„ค๊ณ„ ๋™์‹œ ์ „์†ก์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ณ  ์š”์ฒญ๊ณผ ์‘๋‹ต์ด ์ˆœ์ฐจ์ ์œผ๋กœ ์ด๋ค„์ง„๋‹ค
  • HTTP/2
    • HTTP1.1์„ ์™„์ „ํ•˜๊ฒŒ ์žฌ์ž‘์„ฑํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ํ”„๋กœํ† ์ฝœ์˜ ์„ฑ๋Šฅ์— ์ดˆ์ฒจ์„ ๋งž์ถฐ ์ˆ˜์ •ํ•œ ๋ฒ„์ „ ๊ธฐ๋ณธ์ ์œผ๋กœ connection ํ•œ ๊ฐœ๋กœ ๋™์‹œ์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฉ”์‹œ์ง€๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์‘๋‹ต์€ ์ˆœ์„œ์— ์ƒ๊ด€์—†์ด stream์œผ๋กœ ์ฃผ๊ณ  ๋ฐ›๋Š”๋‹ค
  • AJP
    • "Apache JServ Protocol"์˜ ์•ฝ์ž๋กœ, Tomcat๊ณผ ์›น ์„œ๋ฒ„(์ฃผ๋กœ Apache) ๊ฐ„์˜ ํ†ต์‹ ์„ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ๋กœ Web์„œ๋ฒ„์ธ Apache์—์„œ ์–ด๋–ค ํฌํŠธ๋ฅผ ๋“ค์–ด์˜ค๋ฉด ํฌํŠธํฌ์›Œ๋”ฉํ•  ์ง€์— ๋Œ€ํ•œ ํฌํŠธ ์„ค์ •์„ํ•˜๊ณ  Tomcat๋„ ์ด์— ๋Œ€ํ•œ ๊ฑธ ๋ฐ›๊ธฐ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ ์„ค์ • ๋ฐ ํฌํŠธ ๊ฐœ๋ฐฉ์„ ํ•œ๋‹ค
<!-- Apache ์„ค์ • -->
<VirtualHost *:80>
    ServerName yourdomain.com
    # ๊ธฐํƒ€ ์„ค์ •

    ProxyPass / ajp://localhost:8009/    # Tomcat๊ณผ์˜ AJP ์—ฐ๊ฒฐ ์„ค์ •
    ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>

<!-- Tomcat ์„ค์ • -->
<Connector protocol="AJP/1.3" port="8009" redirectPort="8443" />


์œ„ ํ”„๋กœํ† ์ฝœ์˜ ๋™์ž‘ ๋ฐฉ์‹ ์„ค์ •
- BIO : Tomcat 7 ๊ธฐ๋ณธ ๋ฐฉ์‹ ํ•˜๋‚˜์˜ Thread๊ฐ€ ํ•˜๋‚˜์˜ Connection์„ ๋‹ด๋‹น
- NIO :  Tomcat 8.5 ๊ธฐ๋ณธ ๋ฐฉ์‹ ํ•˜๋‚˜์˜ Thread๊ฐ€ ํ•˜๋‚˜ ์ด์ƒ์˜ Connection์„ ๋‹ด๋‹น
- APR :  10.x ๋ฒ„์ „ ๋ถ€ํ„ฐ ARP ๋ฐฉ์‹ ์‚ญ์ œ

<Connector port="7104" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="7004" URLEncoding="UTF-8" />

 

 

๐Ÿ“Thread Pool ์„ค์ •

maxThreads : Connector๊ฐ€ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ Thread ์ˆ˜
maxConnections : ๋™์‹œ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅํ•œ ์ตœ๋Œ€ Connection ์ˆ˜
maxSpareThreads : ์ตœ์†Œ๋กœ ์‹คํ–‰์„ ์œ ์ง€ํ•  thread ์ˆ˜
acceptCount : thread๊ฐ€ ๊ฝ‰ ์ฐผ์„ ๋•Œ queue์— ์ €์žฅ ๊ฐ€๋Šฅํ•œ ์ตœ๋Œ€ request ์ˆ˜

Thread Pool
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150", maxConnections >
๊ณต์œ  Thread Poll
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>

 

 

๐Ÿ“ Engine

name : Engine์˜ ์œ ์ผํ•œ ์ด๋ฆ„์œผ๋กœ Log๋ฅผ ๋‚จ๊ธธ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
defaultHost ?

<Engine name="Catalina" defaultHost="localhost">

 

 

๐Ÿ“Host

name : ์œ ์ผํ•œ ๊ฐ€์ƒ Host๋ช… (http://hostname/~)
appBase : app ํด๋” (default webapps) Host๋งˆ๋‹ค ๋‹ค๋ฅธ appBase๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. (์—ฌ๋Ÿฌ๊ฐœ Domain ํšจ์œจ์  ๊ด€๋ฆฌ๊ฐ€๋Šฅ)
autoDeploy : appBase์— ๋ณ€๋™์‚ฌํ•ญ์ด ์žˆ์„ ๋•Œ ์ž๋™์œผ๋กœ Deploy(๋ฐฐํฌ) ํ•ด์ค€๋‹ค.
unpackWARs : warํŒŒ์ผ deploy ์„ค์ • ์—ฌ๋ถ€

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

 

 

๐Ÿ“Context

Host์•ˆ์— ์žˆ์œผ๋ฉฐ ํ•˜๋‚˜์˜ WebApplication์ด๋ฉฐ ์ฃผ๋กœ .war ํ˜•ํƒœ๋กœ ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค.

docBase : ํ˜ธ์ถœํ•  ๊ฒฝ๋กœ URI์ด๋‹ค. (/ABC/testing.jsp ํ˜ธ์ถœ์‹œ /webapps/DEF/testing.jsp๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋œ๋‹ค.)

path : ์‹ค์ œ ํ˜ธ์ถœ์‹œํ‚ฌ ๊ฒฝ๋กœ์ด๋‹ค

๋งŒ์•ฝ Context๊ฐ€ ์—†์œผ๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ docBase๋Š” webapps์•ˆ์— ์žˆ๋Š” ํด๋” ์ด๋ฆ„์„ ๋”ฐ๋ผ๊ฐ€๊ฒŒ ๋œ๋‹ค.

์ฆ‰, webapps/ABC ํด๋”๊ฐ€ ์กด์žฌ์‹œ /ABC/ ์ด๋Ÿฐ์‹์œผ๋กœ ํ˜ธ์ถœํ•จ

<Host name="localhost" appBase="webapps"
            unpackWARs="true" autoDeploy="true">
  <Context docBase="ABC" path="/DEF" reloadable="true"></Context>

 

 

 

 

๐Ÿ”— ์ฐธ๊ณ  ๋ฐ ์ถœ์ฒ˜

https://velog.io/@hyunjae-lee/Tomcat-2-%EA%B5%AC%EC%A1%B0

 

Tomcat - (2) ๊ตฌ์กฐ

Tomcat์˜ ๊ตฌ์กฐ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ด…๋‹ˆ๋‹ค.

velog.io

 

https://bogyum-uncle.tistory.com/m/219

 

[Tomcat] server.xml ๊ตฌ์กฐ

ํ†ฐ์บฃ์˜ server.xml ์€ ๋ฉ”์ธ ์„ค์ • ํŒŒ์ผ์ด๋ฉฐ, Tomcat startup ์ดˆ๊ธฐ ์„ค์ •์„ ๋ช…์„ธํ•˜๋Š” ์ฑ…์ž„์ด ์žˆ์Œ 1. server.xml ํƒœ๊ทธ ์˜ˆ์‹œ 2. ํƒœ๊ทธ ์ƒ์„ธ ํƒœ๊ทธ ์„ค๋ช… Server root element, shutdown port ์ง€์ •, ์ „์ฒด ์„ค์ •ํŒŒ์ผ์˜..

bogyum-uncle.tistory.com

https://ijbgo.tistory.com/m/26

 

HTTP/1.1 VS HTTP/2

HTTP/1.1 ๋™์ž‘ ๋ฐฉ์‹ HTTP/1.1๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ Connection๋‹น ํ•˜๋‚˜์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌ ํ•˜๋„๋ก ์„ค๊ณ„๋™์‹œ ์ „์†ก์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๊ณ  ์š”์ฒญ๊ณผ ์‘๋‹ต์ด ์ˆœ์ฐจ์ ์œผ๋กœ ์ด๋ค„์งHTTP ๋ฌธ์„œ ์•ˆ์— ํฌํ•จ๋œ ๋‹ค์ˆ˜์˜ ๋ฆฌ์†Œ์Šค (Images, CSS, Script)

ijbgo.tistory.com


https://velog.io/@wiostz98kr/HTTP1.1%EA%B3%BC-HTTP2.0%EC%9D%98-%EC%B0%A8%EC%9D%B4-e2v4x4t1