제8장 — 모듈

Last Updated: 2026-11-30 14:51 Views: 2

8.1 내장 모듈

내장 모듈은 메인 바이너리에 컴파일되며, 구성은 modules.<name> 아래 또는 최상위 로케이션 키로 지정합니다. 용도별:

범주 모듈
HTTP 코어 http_staticfile, http_proxy, http_rewrite, http_headers, http_accesslog
프로토콜 클라이언트 http_fastcgi, http_uwsgi, http_scgi, http_grpc, http_memcached
보안 http_waf, http_access, http_auth_basic, http_auth_request, http_auth_jwt, http_secure_link, http_security_headers, http_limit, http_error_guard
필터 및 압축 http_gzip, http_gunzip, http_brotli, http_zstd, http_sub, http_addition, http_ssi, http_charset, http_minify, http_concat
미디어 및 콘텐츠 http_image_thumb, http_mp4, http_empty_gif, http_stub_status, http_nchan, http_upload
변수 및 분할 http_map, http_geo, http_geoip, http_split_clients, http_realip, http_userid, http_browser, http_referer
관측성 및 보호 http_otel, http_logsink, http_mirror, http_sysguard

모듈은 GET /api/modules와 콘솔의 “모듈” 페이지에서 이름, 버전, 설명, 로드 상태와 함께 나열됩니다.

8.2 외부 동적 모듈

외부 모듈은 네이티브 동적 라이브러리(cdylib)입니다. Linux/FreeBSD는 .so, macOS는 .dylib, Windows는 .dll로, 안정적인 C ABI v2로 로드됩니다——모듈은 wxserver_module_v2 심볼(manifest JSON + on_hook 콜백)을 내보내고, 필요에 따라 wxserver_body_filter_v1(스트리밍 바디 필터)과 wxserver_action_v1(콘솔 액션)도 내보냅니다.

임의의 Rust crate을 cdylib으로 빌드합니다:

cargo build --release --manifest-path /path/to/plugin/Cargo.toml
# 출력: target/release/lib<name>.so / .dylib / .dll

구성에서 활성화하고 모듈의 전역 구성을 전달합니다(manifest의 config schema로 검증됨):

external_modules = [{ path = "/usr/share/wxserver/modules/libexample.so", enabled = true }]

modules = { example = { greeting = "hi" } }

manifest는 모듈의 훅, 활성화 조건, 구성 스키마, 콘솔 폼/용어를 선언합니다. 호스트는 manifest, 종속성(depends. 필수 종속 누락 시 시작 실패), 스코프 구성을 통합 검증합니다. 선택적으로 sha256 고정과 signature/signature_key Ed25519 서명 검증을 사용할 수 있습니다(공개 키는 plugin_trust.keys). 모듈 추가·제거는 구성 리로드로 반영됩니다. 샘플 플러그인은 소스 트리의 plugins/example_echo/에 있습니다. C ABI 세부 사항은 docs/plugin-abi-c.md를 참조하십시오.

8.3 모듈 개발 인터페이스

내장 모듈은 modules/<name>/ 크레이트에 있으며, modules/common 헬퍼로 manifest을 선언하고 해당 페이즈의 hook trait을 구현한 뒤 register_entry!로 자가 등록합니다 (linkme 분산 슬라이스). 외부 모듈은 C ABI로 동일한 manifest 모델을 구현합니다.

페이즈별 호출 방식:

페이즈 trait / 메커니즘 대표 용도
Rewrite BuiltinHandler / AsyncBuiltinHandler 경로 재작성, 리디렉션
PreAccess / Access 동일 속도 제한, 인증, IP 제어
Content ContentBuiltin(location.type으로 디스패치) 프록시, FastCGI, 정적 파일
HeaderFilter BuiltinHandler 헤더 필터
BodyFilter BuiltinHandler / AsyncBodyBuiltin / 외부 wxserver_body_filter_v1 압축, 치환, SSI
Log BuiltinHandler(LogMeta 포함) 액세스 로그
WAF Phase::WafRequest/WafResponse 차단(blocked 반환)
service ServiceBuiltin(plugin::start_services가 시작) metrics/otel/stream/mail

페이즈 순서는 고정입니다: Rewrite → PreAccess → Access → Content → HeaderFilter → BodyFilter → Log. hook은 conditions(methods/path/host/header/cookie/status/tls/ cidr)와 priority를 선언할 수 있고, HookOutcome은 Continue / Handled(Resp) / InternalRedirect입니다. 설계는 docs/plugin-architecture.md, 구현 상태는 docs/plugin-architecture.md를 참조하십시오.

8.4 모듈 비활성화

내장 모듈은 재빌드 없이 비활성화할 수 있습니다:

http = {
  disabled_modules = ["http_waf", "http_zstd"],
  servers = [{ disabled_modules = ["http_image_thumb"] }],
}

비활성화된 모듈은 해당 페이즈와 content 핸들러를 실행하지 않습니다. content 모듈을 비활성화하기 전에 이를 참조하는 모든 location.type을 제거해야 합니다. 그렇지 않으면 wxserver -t와 콘솔 저장 검증이 실패합니다. 런타임 비활성화는 모듈이 초기화한 리소스를 강제 해제하지 않습니다. 완전히 회수하려면 프로세스를 재시작하십시오. 필수 종속이 비활성화되면 시작이 실패하고, 선택 종속은 경고만 발생합니다.

← Previous Article 제7장 — 운영 및 관리 Next Article → 제9장 — 설정 참조

Comments

No comments yet