• Nginx http realip 모듈 : https://nginx.org/en/docs/http/ngx_http_realip_module.html
  • ngx_http_realip_module 모듈은 클라이언트 주소와 선택적 포트를 지정된 헤더 필드에 전송된 주소로 변경하는 데 사용
  • ngx_http_realip_module 모듈은 기본적으로 빌드되지 않으며, --with-http_realip_module 구성 매개변수를 사용하여 활성화

  • 구성 예시
    set_real_ip_from  192.168.1.0/24;
    set_real_ip_from  192.168.2.1;
    set_real_ip_from  2001:0db8::/32;
    real_ip_header    X-Forwarded-For;
    real_ip_recursive on;

 

set_real_ip_from 지시자

  • nginx가 지정된 범위 내의 프록시 서버에서 실제 방문자의 IP를 가져 오도록 지시
  • 올바른 대체 주소를 전송하는 것으로 알려진 신뢰할 수 있는 주소를 정의
  • 특수 값인 unix:를 지정하면 모든 UNIX 도메인 소켓이 신뢰
  • 호스트 이름(1.13.1)을 사용하여 신뢰할 수 있는 주소를 지정 가능
  • IPv6 주소는 버전 1.3.0 및 1.2.1부터 지원

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    set_real_ip_from address | CIDR | unix:;

 

real_ip_header 지시자

  • nginx는 주어진 주소에서 클라이언트의 IP 주소를 선택
  • 클라이언트 주소를 대체하는 데 사용될 request 헤더 필드 값을 정의
  • 선택적 포트가 포함된 request 헤더 필드 값은 클라이언트 포트(1.11.0)를 대체하는 데에도 사용
  • 주소와 포트는 RFC 3986에 따라 지정 → 참고 자료 : RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax (ietf.org)
  • proxy_protocol 매개변수(1.5.12)는 클라이언트 주소를 프록시 프로토콜 헤더(PROXY protocol header)의 주소로 변경
  • listen 지시어에 proxy_protocol 파라미터를 설정하여 PROXY 프로토콜을 활성화

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    real_ip_header field | X-Real-IP | X-Forwarded-For | proxy_protocol;
  • 사용 예시
    ## 기본 설정
    real_ip_header X-Real-IP;

 

real_ip_recursive 지시자

  • 프록시 서버의 IP가 방문자의 IP 주소로 대체
  • 재귀 검색(recursive search)을 사용하지 않으면 신뢰할 수 있는 주소 중 하나와 일치하는 원래 클라이언트 주소가 real_ip_header 지시어로 정의된 request 헤더 필드에 전송된 마지막 주소로 대체
  • 재귀 검색(recursive search)이 활성화된 경우 신뢰할 수 있는 주소 중 하나와 일치하는 원본 클라이언트 주소는 request 헤더 필드에 전송된 마지막 신뢰할 수 없는 주소로 대체
  • real_ip_recursive 지시어는 버전 1.3.0과 1.2.1에 등장

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    real_ip_recursive on | off;
  • 사용 예시
    ## 기본 설정
    real_ip_recursive off;

 

ngx_http_realip_module모듈의 내장 변수

1. $realip_remote_addr 변수

  • keeps the original client address (1.9.7)
  • 원래 클라이언트 주소 유지 (1.9.7)

 

2. $realip_remote_port 변수

  • keeps the original client port (1.11.0)
  • 원래 클라이언트 포트(1.11.0)를 유지

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_referer_module 모듈  (0) 2023.09.23
ngx_http_secure_link_module 모듈  (0) 2023.09.23
ngx_http_slice_module 모듈  (0) 2023.09.22
ngx_http_split_clients_module 모듈  (0) 2023.09.22
ngx_http_sub_module 모듈  (0) 2023.09.22
 

Module ngx_http_slice_module

Module ngx_http_slice_module The ngx_http_slice_module module (1.9.8) is a filter that splits a request into subrequests, each returning a certain range of response. The filter provides more effective caching of big responses. This module is not built by d

nginx.org

 

  • ngx_http_slice_module 모듈(1.9.8)은 요청을 하위 요청으로 분할하고 각각의 응답 범위를 반환
    대용량 응답의 더 효과적인 캐싱을 제공
  • --with-http_slice_module 구성 매개변수로 활성화

 

 

slice 지시자

  • slice 지시자를 통해 응답 조각의 크기를 설정
  • slice 0 값은 응답을 조각으로 나누지 않음
  • 너무 낮은 값은 과도한 메모리 사용 및 대량 파일 열기로 이어질 수 있음
  • Range 요청 헤더 필드로 $slice_range 변수를 프록시 서버로 전달
  • 캐싱이 활성화되어 있으면 $slice_range를 캐시 키에 추가하고 206 상태 코드를 가진 응답의 캐싱을 활성화

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    slice size;
  • 사용 예시
    ## 기본 설정
    slice 0;

 

 

slice 예제 구성

  • 응답은 1MB 캐시 가능한 조각으로 설정
    location / {
        slice             1m;
        proxy_cache       cache;
        proxy_cache_key   $uri$is_args$args$slice_range;
        proxy_set_header  Range $slice_range;
        proxy_cache_valid 200 206 1h;
        proxy_pass        http://localhost:8000;
    }

 

 

ngx_http_slice_module 모듈의 내장 변수 → $slice_range

  • HTTP 바이트 범위 형식의 현재 조각 범위
  • 예시 : bytes=0-1048575.

 

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_secure_link_module 모듈  (0) 2023.09.23
ngx_http_realip_module 모듈  (0) 2023.09.23
ngx_http_split_clients_module 모듈  (0) 2023.09.22
ngx_http_sub_module 모듈  (0) 2023.09.22
ngx_upstream_jdomain 모듈  (0) 2023.09.21
 

Module ngx_http_split_clients_module

Module ngx_http_split_clients_module The ngx_http_split_clients_module module creates variables suitable for A/B testing, also known as split testing. Example Configuration http { split_clients "${remote_addr}AAA" $variant { 0.5% .one; 2.0% .two; * ""; } s

nginx.org

 

  • ngx_http_split_clients_module 모듈은 분할 테스트라고도 하는 A/B 테스트에 적합한 변수를 생성함

 

split_clients 지시자

  • 구성 예시
    http {
        split_clients "${remote_addr}AAA" $variant {
                       0.5%               .one;
                       2.0%               .two;
                       *                  "";
        }
        server {
            location / {
                index index${variant}.html;
            }
        }
     }
  • original 문자열의 값은 MurmurHash2를 사용하여 해시

  • 예시)
    • 0에서 21474835(0.5%)의 해시 값은 $variant 변수의 값 ".one"에 해당
    • 21474836에서 107374180(2%)의 해시 값은 ".two"에 해당
    • 107374181에서 4294967295의 해시 값은 ""(빈 문자열)에 해당

  • 문맥 : http
  • 사용 문법
    ## 문법
    split_clients string $variable { ... }

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_realip_module 모듈  (0) 2023.09.23
ngx_http_slice_module 모듈  (0) 2023.09.22
ngx_http_sub_module 모듈  (0) 2023.09.22
ngx_upstream_jdomain 모듈  (0) 2023.09.21
ngx_http_image_filter_module 모듈  (0) 2023.09.21
 

Module ngx_http_sub_module

Module ngx_http_sub_module The ngx_http_sub_module module is a filter that modifies a response by replacing one specified string by another. This module is not built by default, it should be enabled with the --with-http_sub_module configuration parameter.

nginx.org

 

  • ngx_http_sub_module 모듈은 지정된 문자열을 다른 문자열로 대체하여 응답을 수정하는 필터
  • ngx_http_sub_module 모듈은 기본적으로 빌드되지 않으며 --with-http_sub_module 구성 매개변수를 사용하여 사용할 수 있도록 설정 필요

  • 구성 예시
      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;
      }

 

 

sub_filter 지시자

  • 바꿀 문자열과 대체 문자열을 설정
  • 바꿀 문자열은 대소문자를 무시
  • 대체할 문자열(The string to replace)과 대체 문자열(replacement string)은 변수를 포함할 수 있음
  • 동일한 구성 수준(same configuration level)에서 여러 개의 sub_filter 지시어를 지정 가능
  • sub_filter 지시어는 현재 수준(current level)에 정의된 sub_filter 지시어가 없는 경우에만 이전 구성 수준(previous configuration level)에서 상속됨

  • 문맥 : http, server, location
  • 사용 문법
      ## 문법
      sub_filter string replacement;

 

 

sub_filter_last_modified 지시자

  • 응답 캐싱(response caching)을 용이하게 하기 위해 교체하는 동안 원본 응답(original response)의 "Last-Modified" 헤더 필드를 보존할 수 있음
  • 기본적으로 헤더 필드(header field)는 처리 중에 응답의 내용(contents of the response)이 수정되면 제거됨

  • 문맥 : http, server, location
  • 사용 문법
      ## 문법
      sub_filter_last_modified on | off;
  • 사용 예시
      ## 기본 설정
      sub_filter_last_modified off;

 

 

sub_filter_once 지시자

  • 대체할 각 문자열(each string to replace)을 한 번만 찾을지 반복해서 찾을지 여부를 나타냄

  • 문맥 : http, server, location
  • 사용 문법
      ## 문법
      sub_filter_once on | off;
  • 사용 예시
      ## 기본 설정
      sub_filter_once on;

 

 

sub_filter_types 지시자

  • 응답(responses)에서 "text/html" 외에 지정된 MIME 유형으로 문자열을 대체할 수 있도록 함
  • 특수 값(special value)인 "*"는 모든 MIME 유형과 일치

  • 문맥 : http, server, location
  • 사용 문법
      ## 문법
      sub_filter_types mime-type ...;
  • 사용 예시
      ## 기본 설정
      sub_filter_types text/html;

 

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_slice_module 모듈  (0) 2023.09.22
ngx_http_split_clients_module 모듈  (0) 2023.09.22
ngx_upstream_jdomain 모듈  (0) 2023.09.21
ngx_http_image_filter_module 모듈  (0) 2023.09.21
ngx_http_gzip_static_module 모듈  (1) 2023.09.21
 

Upstream Domain Resolve | NGINX

Upstream Domain Resolve Description ngx_upstream_jdomain - an upstream module that resolves an upstream domain name asynchronously. Its buffer has the latest IPs of the backend domain name and it integrates with the configured load balancing algorithm (lea

www.nginx.com

 

 

GitHub - nicholaschiasson/ngx_upstream_jdomain: An asynchronous domain name resolution module for nginx upstream.

An asynchronous domain name resolution module for nginx upstream. - GitHub - nicholaschiasson/ngx_upstream_jdomain: An asynchronous domain name resolution module for nginx upstream.

github.com

 

ngx_upstream_jdomain 모듈이란

  • ngx_upstream_jdomain 모듈은 nginx 업스트림 도메인 네임을 비동기적으로 확인하는 업스트림 모듈
  • 업스트림 블록에서 도메인 이름을 사용할 수 있으며 도메인 이름이 동적으로 확인 → 업스트림이 DNS 항목 업데이트에 탄력적으로 대응 가능
  • ngx_upstream_jdomain 모듈은 일정 간격으로 DNS 확인을 자동으로 수행하지 않음 → 주어진 업스트림에 대한 요청에 따라 DNS 확인
  • nginx가 jdomain 업스트림에 바인딩된 연결을 제공하고 구성된 간격(interval)이 경과한 경우 모듈은 DNS 조회를 수행함

 

  • ngx_upstream_jdomain 모듈은 다른 업스트림 범위(upstream scope) 지시어와 호환
    1. 여러 jdomain 지시어(multiple jdomain directives)
    2. 여러 서버 지시어(multiple server directives)
    3. keepalive
    4. 로드 밸런싱 지시어(load balancing directives)
    5. 등등(etc.)

 

  • 업스트림 블록에 다른 로드 밸런싱 방법을 지정하지 않는 한 ngx_upstream_jdomain 모듈은 nginx 코어에 내장된 기본 라운드 로빈 로드 밸런싱 알고리즘을 사용
  • 버퍼에는 백엔드 도메인 이름(backend domain name)의 최신 IP가 구성되어 있으며, 로드 밸런싱 알고리즘(최소_conn, 해시 등) 또는 명시적으로 정의되지 않은 경우 내장된 라운드 로빈과 통합함
  • 매 간격(기본값은 1초)마다 도메인 이름을 확인(질의)
  • 도메인 네임을 확인하지 못하면 버퍼는 마지막으로 성공적으로 확인된 IP를 유지하거나 사용자가 지정한 백업 서버 IP를 사용

 

 

※ 대체 로드 밸런싱 알고리즘(alternate load balancing algorithm)을 지정하는 경우 업스트림 블록의 jdomain 지시어 앞에 지정 필요

  • 앞에 지정하지 않는 경우 런타임 중에 nginx가 충돌 발생
  • 많은 로드 밸런싱 모듈이 내장된 라운드 로빈을 명시적으로 확장
  • jdomain 지시어 이후에 대체 로드 벨런싱 알고리즘을 지정하면, jdomain 초기화 핸들러를 방해 → jdomain은 로드 밸런서 모듈
  • 단, 모든 로드 밸런서 모듈에 해당하는 것은 아니지만, 안전을 위해 jdomain을 뒤에 배치하는 것이 좋음(jdomain 앞에 대체 로드 밸런싱 알고리즘 취이 필요)

 

※ ngx_upstream_jdomain 모듈의 비차단 특성(non blocking nature)과 들어오는 요청에 의해 DNS resolve 트리거

  • resolve를 요청하는 트리거는 실제로는 DNS 조회가 발생하기 전에 확인되어 캐시된 업스트림으로 전달
  • 시나리오에 따라 업스트림의 상태를 변경할 때 일회성 장애가 발생할 수 있음
  • 업스트림의 원활한 전환을 보장하기 위해 염두에 두어야 함

 

 

ngx_upstream_jdomain 시놉시스(Synopsis)

1. ngx_upstream_jdomain 문법

jdomain <domain-name> [port=80] [max_ips=4] [interval=1] [strict]

 

2. nginx_upstream_jdomain 위치

  • Context: upstream

 

3. nginx_upstream_jdomain 속성 설명

속성 설명
port - 백엔드의 listen 포트
- Default: 80
max_ips - IP 버퍼 크기(IP buffer size)
- 캐시할 최대 확인된 IP 수
- Default: 4
interval - 도메인 이름 resolve 걸리는 시간(초)
- Default: 1
ipver - 정의된 경우 패밀리 IPv4 또는 IPv6 주소만 사용
- Default: 0
strict - DNS resolve이 성공하고 주소를 반환해야 함
- 그렇지 않으면 기본 서버와 피어(server and peers)를 다운으로 표시하고 업스트림 블록에 다른 서버가 있는 경우 강제로 사용

- 확인 실패 경우
  1. timeout
  2. DNS server failure
  3. connection refusals
  4. response with no addresses

 

 

ngx_upstream_jdomain 모듈 설치(Installation)

 

 

ngx_upstream_jdomain 사용 예시

resolver 8.8.8.8; # Your Local DNS Server

# Basic upstream using domain name defaulting to port 80.
upstream backend_01 {
    jdomain example.com;
}

# Basic upstream specifying different port.
upstream backend_02 {
    jdomain example.com port=8080;
}

# Upstream with a backup server to use in case of host not found or format
# errors on DNS resolution.
upstream backend_03 {
    server 127.0.0.2 backup;
    jdomain example.com;
}

# Upstream which will use backup for any and all DNS resolution errors.
upstream backend_04 {
    server 127.0.0.2 backup;
    jdomain example.com strict;
}

# Upstream which will use backup for any and keepalive.
upstream backend_05 {
    server 127.0.0.2:55555 backup;
    jdomain example.com;
    keepalive 8;
}

server {
    listen 127.0.0.2:80;
    return 502 'An error.';
}

 

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_split_clients_module 모듈  (0) 2023.09.22
ngx_http_sub_module 모듈  (0) 2023.09.22
ngx_http_image_filter_module 모듈  (0) 2023.09.21
ngx_http_gzip_static_module 모듈  (1) 2023.09.21
ngx_http_gunzip_module 모듈  (0) 2023.09.21
 

Module ngx_http_image_filter_module

Module ngx_http_image_filter_module The ngx_http_image_filter_module module (0.7.54+) is a filter that transforms images in JPEG, GIF, PNG, and WebP formats. This module is not built by default, it should be enabled with the --with-http_image_filter_module

nginx.org

 

  • ngx_http_image_filter_module모듈(0.7.54+)은 JPEG, GIF, PNG 및 WebP 형식의 이미지를 변환하는 필터
  • --with-http_image_filter_module 모듈은 기본적으로 빌드되지 않으며 구성 매개변수로 활성화
  • nginx의 nginx-module-image-filter 모듈에 필요한 library들을 미리 다운로드 → 다운되지 않아서 해당 내용 확인 필요
  • 이미지를 변환하려면 libgd라이브러리를 WebP 지원으로 컴파일필요
      $ yum install -y gd gd-devel libc.so.6 libgd.so.2

 

 

ngx_http_image_filter_module 모듈 사용 예시

location /img/ {
    proxy_pass   http://backend;
    image_filter resize 150 100;
    image_filter rotate 90;
    error_page   415 = /empty;
}

location = /empty {
    empty_gif;
}

 

 

image_filter 지시어

  • 이미지에 수행할 변환 유형을 설정
  • 문맥: location
  • 사용 문법과 사용 예시
      # 문법 : image_filter 설정값
      image_filter off;
      image_filter test;
      image_filter size;
      image_filter rotate 90 | 180 | 270;
      image_filter resize width height;
      image_filter crop width height;

 

  • image_filter 설정값 종류
    1. off
      • 모듈 처리를 종료

    2. test
      • 응답이 JPEG, GIF, PNG 또는 WebP 형식의 이미지인지 확인
      • 그렇지 않으면 415(지원되지 않는 미디어 유형) 오류가 반환

    3. size
      • 이미지에 대한 정보를 JSON 형식으로 출력 → 출력 예시 : { "img" : { "width": 100, "height": 100, "type": "gif" } }
      • 오류 출력 → 출력 예시 : {}

    4. rotate 90|180|270
      • 지정된 각도만큼 이미지를 시계 반대 방향으로 회전함
      • 매개변수 값은 변수를 포함할 수 있음
      • 이 모드는 단독으로 또는 resize및 crop변환과 함께 사용 가능

    5. resize width height
      • 이미지를 지정된 크기로 비례적으로 축소함
      • 한 차원만 줄이려면 다른 차원을 " -"로 지정할 수 있음
      • 오류가 발생하면 서버는 코드 415(지원되지 않는 미디어 유형)를 반환
      • 매개변수 값에는 변수가 포함될 수 있음
      • rotate 매개변수와 함께 사용하면, 이미지의 크기를 축소한 후에 rotate 회전이 발생.

    6. crop width height
      • 비례적으로 이미지를 줄이고 불필요한 가장자리를 다른 면으로 자름 → 해당 이미지를 정해진 크기로 자르는 기능
      • 한 차원만 줄이려면 다른 차원을 " -"로 지정할 수 있음
      • 오류가 발생하면 서버는 코드 415(지원되지 않는 미디어 유형)를 반환
      • 매개변수 값에는 변수가 포함될 수 있음
      • rotate 매개변수와 함께 사용하면, 이미지의 크기를 축소한 후에 rotate 회전이 발생.

 

image_filter_buffer 지시어

  • 이미지를 읽는 데 사용되는 버퍼의 최대 크기를 설정함
  • 크기를 초과하면 서버에서 오류 415(지원되지 않는 미디어 유형)를 반환
  • 문맥: http, server, location
  • 사용 문법과 사용 예시
      # 문법 : image_filter_buffer size;
      image_filter_buffer 1M;

 

image_filter_interlace 지시어

  • 활성화하면 최종 이미지가 인터레이스됨
  • JPEG의 경우 최종 이미지는 "progressive JPEG" 형식이 됨
  • 문맥: http, server, location
  • image_filter_interlace 지시문은 버전 1.3.15에서부터 지원
  • 사용 문법과 사용 예시
      # 문법 : image_filter_interlace on | off;
      image_filter_interlace off;

 

image_filter_jpeg_quality 지시어

  • 변환된 JPEG 이미지 중 원하는 화질을 설정
  • 허용되는 값은 1에서 100 사이
  • 값이 작을수록 일반적으로 이미지 품질이 낮고 전송할 데이터가 적음
  • 최대 권장 값은 95임
  • 매개변수 값은 변수를 포함할 수 있음
  • 문맥: http, server, location
  • 사용 문법과 사용 예시
      # 문법 : image_filter_jpeg_quality quality;
      image_filter_jpeg_quality 75;

 

image_filter_sharpen 지시어

  • 최종 이미지의 선명도를 높일 수 있음
  • 선명도 백분율은 100을 초과할 수 있음
  • 0 값은 선명도를 비활성화
  • 매개변수 값은 변수를 포함할 수 있음
  • 문맥: http, server, location
  • 사용 문법과 사용 예시
      # 문법 : image_filter_sharpen percent;
      image_filter_sharpen 0;

 

image_filter_transparency 지시어

  • GIF 이미지 또는 PNG 이미지를 팔레트로 지정된 색으로 변환할 때 투명도를 유지해야 하는지 여부를 정의
  • 투명도의 손실은 더 나은 품질의 이미지를 만듦
  • PNG의 알파 채널 투명도는 항상 유지됨
  • 문맥: http, server, location
  • 사용 문법과 사용 예시
      # 문법 : image_filter_transparency on|off;
      image_filter_transparency off;

 

image_filter_webp_quality 지시어

  • 변환된 WebP 영상의 원하는 화질을 설정함
  • 허용되는 값은 1에서 100 사이의 범위임
  • 값이 작을수록 일반적으로 이미지 품질이 낮고 전송할 데이터도 적다는 것을 의미함
  • 매개변수 값은 변수를 포함할 수 있음
  • image_filter_webp_quality 지시문은 버전 1.11.6에서부터 지원
  • 문맥: http, server, location
  • 사용 문법과 사용 예시
      # 문법 : image_filter_webp_quality quality;
      image_filter_webp_quality 80;

 

참고 자료

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_sub_module 모듈  (0) 2023.09.22
ngx_upstream_jdomain 모듈  (0) 2023.09.21
ngx_http_gzip_static_module 모듈  (1) 2023.09.21
ngx_http_gunzip_module 모듈  (0) 2023.09.21
ngx_http_empty_gif_module 모듈  (0) 2023.09.21
 

Module ngx_http_gzip_static_module

Module ngx_http_gzip_static_module The ngx_http_gzip_static_module module allows sending precompressed files with the “.gz” filename extension instead of regular files. This module is not built by default, it should be enabled with the --with-http_gzip

nginx.org

 

  • ngx_http_gzip_static_module 모듈을 사용하면 일반 파일 대신 파일 확장자가 ".gz"인 미리 압축된 파일을 전송할 수 있음
  • ngx_http_gzip_static_module 모듈은 기본적으로 빌드되지 않으며 --with-http_gzip_static_module 구성 매개변수를 사용하여 사용하도록 설정
  • gzip_static은 정적 파일을 미리 gzip으로 압축해 두면 압축 프로세싱 과정 없이 즉시 해당 압축 파일을 전송함
  • gzip_static 사용 시 CPU 점유율이 낮아지고 성능이 향상됨
  • 예시) test.js파일에 대한 요청이 올 경우 test.js.gz를 찾아서 해당 파일이 존재하면 압축된 버전을 전송하고, 없으면 원본 파일을 압축한 뒤에 전송

 

  • 구성 예시
      gzip_static  on;
      gzip_proxied expired no-cache no-store private auth;

 

 

gzip_static 지시자

 

  • "always" 값(1.3.6)을 사용하면 클라이언트가 지원하는지 확인하지 않고 모든 경우에 gzip 파일이 사용
  • gzip_static 옵션은 디스크에 압축되지 않은 파일(uncompressed files)이 없거나 ngx_http_gunzip_module이 사용되는 경우에 유용
  • 파일은 gzip 명령 또는 기타 호환되는 명령을 사용하여 압축할 수 있음
  • 원본 파일과 압축 파일의 수정 날짜(modification data) 및 시간(time)은 동일하게 하는 것이 좋음

 

  • 문맥 : http, server, location
  • 사용 문법
      # 문법
      gzip_static on | off | always;
  • 사용 예시
      # 사용 예시
      gzip_static off;

 

참고 자료

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_upstream_jdomain 모듈  (0) 2023.09.21
ngx_http_image_filter_module 모듈  (0) 2023.09.21
ngx_http_gunzip_module 모듈  (0) 2023.09.21
ngx_http_empty_gif_module 모듈  (0) 2023.09.21
ngx_http_addition_module 모듈  (0) 2023.09.21
 

Module ngx_http_gunzip_module

Module ngx_http_gunzip_module The ngx_http_gunzip_module module is a filter that decompresses responses with “Content-Encoding: gzip” for clients that do not support “gzip” encoding method. The module will be useful when it is desirable to store da

nginx.org

 

  • ngx_http_gunzip_module 모듈은 "gzip" 인코딩 방식을 지원하지 않는 클라이언트에 대해 "Content-Encoding: gzip"으로 응답의 압축을 해제하는 필터
  • ngx_http_gunzip_module 모듈은 공간을 절약하고 I/O 비용을 줄이기 위해 데이터를 압축하여 저장하는 것이 바람직할 때 유용
  • ngx_http_gunzip_module 모듈은 기본적으로 빌드되지 않으며, --with-http_gunzip_module 구성 매개변수를 사용하여 활성화

  • 구성 예시
      location /storage/ {
        gunzip on;
        ...
      }

 

 

gunzip 지시자

  • 문맥 : http, server, location
  • 사용 문법
    # 문법
    gunzip on | off;
  • 사용 예시
    # 기본 설정
    gunzip off;

 

 

gunzip_buffers 지시자

  • 응답의 압축을 푸는 데 사용되는 버퍼의 수와 크기를 설정
  • 기본적으로 버퍼 크기는 1개의 메모리 페이지(one memory page)와 같음
  • 플랫폼에 따라 4K 또는 8K

  • 문맥 : http, server, location
  • 사용 문법
    # 문법
    gunzip_buffers number size;
  • 사용 예시
    # 기본 설정
    gunzip_buffers 32 4k|16 8k;

 

 

gunzip 사용 목적

  • 목적
    1. 오리진 → nginx는 gzip 통신
    2. nginx → 사용자는 Accept-Encoding에 gzip(deflate)이 없으면 gunzip해서 보내기

  • 사용자의 gzip content 종류 파악 (location 조정 필요)
      location / {
          gunzip on;   # 압축해제 기능 (기본 포함 되어 있음(현재 docker에))
          gunzip_buffers 16 64k; # 튜닝 필요
          proxy_set_header Accept-Encoding "gzip"; #오리진이 gzip 지원 해야 함.
          set $gaccept 'gzip';
      }

 

 

'Nginx > Nginx 모듈 학습' 카테고리의 다른 글

ngx_http_image_filter_module 모듈  (0) 2023.09.21
ngx_http_gzip_static_module 모듈  (1) 2023.09.21
ngx_http_empty_gif_module 모듈  (0) 2023.09.21
ngx_http_addition_module 모듈  (0) 2023.09.21
ngx_http_access_module 모듈  (0) 2023.09.20

+ Recent posts