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

ngx_http_sub_module 모듈

원문 보기 위키 갱신

ngx_http_sub_module 모듈은 응답에서 문자열 하나를 찾아 다른 문자열로 바꿔 주는 필터(filter) 모듈이에요.

이 모듈은 기본적으로 빌드되지 않으므로, --with-http_sub_module 구성 매개변수로 활성화해야 해요.

출처: 문서

본문

예시 구성 (Example Configuration)

location / {
    sub_filter '<a href="http://127.0.0.1:8080/'  '<a href="https://$host/';
    sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
    sub_filter_once on;
}

지시어 (Directives)

Syntax: sub_filter string replacement;
Default: —
Context: http, server, location

바꿀 문자열과 바꿀 대상(replacement) 문자열을 설정해요. 바꿀 문자열은 대소문자를 무시하고 매칭돼요. 바꿀 문자열(1.9.4)과 대상 문자열에는 변수를 사용할 수 있어요. 같은 구성 레벨에 여러 개의 sub_filter 지시어를 지정할 수 있어요 (1.9.4). 이 지시어들은 현재 레벨에 sub_filter 지시어가 정의되어 있지 않은 경우에만 이전 구성 레벨에서 상속돼요.

Syntax: sub_filter_last_modified on | off;
Default: sub_filter_last_modified off;
Context: http, server, location

이 지시어는 버전 1.5.1에 등장했어요.

대체(replacement) 과정에서 원본 응답의 "Last-Modified" 헤더 필드를 유지해 응답 캐싱을 용이하게 해 줘요.

기본적으로 응답 내용이 처리 중에 수정되므로 해당 헤더 필드는 제거돼요.

Syntax: sub_filter_once on | off;
Default: sub_filter_once on;
Context: http, server, location

바꿀 문자열을 각각 한 번만 찾을지, 반복해서 찾을지를 나타내요.

Syntax: sub_filter_types mime-type ...;
Default: sub_filter_types text/html;
Context: http, server, location

"text/html" 외에 지정된 MIME 타입의 응답에서도 문자열 대체를 활성화해요. 특수 값 "*" 는 어떤 MIME 타입이든 매칭해요 (0.8.29).

더 알아보기 (Learn more)