본문 바로가기
WIKI 기술 지식 베이스

encode 지시문

원문 보기 위키 갱신

encode 지시문 (응답 인코딩/압축)

encode 지시문은 설정된 인코딩으로 응답을 인코딩해요. 인코딩의 대표적인 용도는 압축이에요. Gzip이나 Zstandard 압축으로 응답 크기를 줄일 수 있어요.

출처: Caddy 공식 문서

본문

설정된 인코딩으로 응답을 인코딩해요. 인코딩의 대표적인 용도는 압축이에요.

문법 (Syntax)

encode [<matcher>] [<formats...>] {
	# encoding formats
	gzip [<level>]
	zstd [<level>]

	minimum_length <length>

	match <inline_response_matcher>
}
  • **<formats...>**는 활성화할 인코딩 형식 목록이에요. 여러 인코딩이 활성화되면 요청의 Accept-Encoding 헤더에 따라 인코딩을 선택해요. 클라이언트가 강한 선호(q-factor)가 없으면 첫 번째로 지원되는 인코딩을 사용해요. 생략하면 zstd(선호)와 gzip이 기본으로 활성화돼요.

  • gzip은 Gzip 압축을 활성화하고, 선택적으로 지정된 레벨로 압축해요.

  • zstd는 Zstandard 압축을 활성화하고, 선택적으로 지정된 레벨로 압축해요(가능한 값 = default, fastest, better, best). 기본 압축 레벨은 대략 Zstandard 기본 모드(레벨 3)와 같아요.

  • minimum_length는 응답이 인코딩되기 위해 가져야 하는 최소 바이트 수예요(기본값: 512). Server-sent events 응답(Content-Type: text/event-stream)은 이 임계값을 맞추기 위해 보류되지 않아요. 그 헤더는 즉시 클라이언트로 보내지고, 이벤트는 작성되는 대로 스트리밍돼요.

  • match는 응답 matcher예요. 일치하는 응답만 인코딩돼요. 기본값은 다음과 같아요:

match {
	header Content-Type application/atom+xml*
	header Content-Type application/eot*
	header Content-Type application/font*
	header Content-Type application/geo+json*
	header Content-Type application/graphql+json*
	header Content-Type application/javascript*
	header Content-Type application/json*
	header Content-Type application/ld+json*
	header Content-Type application/manifest+json*
	header Content-Type application/opentype*
	header Content-Type application/otf*
	header Content-Type application/rss+xml*
	header Content-Type application/truetype*
	header Content-Type application/ttf*
	header Content-Type application/vnd.api+json*
	header Content-Type application/vnd.ms-fontobject*
	header Content-Type application/wasm*
	header Content-Type application/x-httpd-cgi*
	header Content-Type application/x-javascript*
	header Content-Type application/x-opentype*
	header Content-Type application/x-otf*
	header Content-Type application/x-perl*
	header Content-Type application/x-protobuf*
	header Content-Type application/x-ttf*
	header Content-Type application/xhtml+xml*
	header Content-Type application/xml*
	header Content-Type font/*
	header Content-Type image/svg+xml*
	header Content-Type image/vnd.microsoft.icon*
	header Content-Type image/x-icon*
	header Content-Type multipart/bag*
	header Content-Type multipart/mixed*
	header Content-Type text/*
}

예시 (Examples)

Gzip 압축을 활성화해요:

encode gzip

Zstandard와 Gzip 압축을 활성화해요(첫 번째라서 Zstandard가 암시적으로 선호됨):

encode zstd gzip

이것이 기본값이므로, 위 설정은 다음과 완전히 동일해요:

encode

전체 사이트에서 file_server가 서빙하는 정적 파일을 압축하려면:

example.com {
	root /srv
	encode
	file_server
}

더 알아보기 (Learn more)