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
 

Module ngx_http_empty_gif_module

Module ngx_http_empty_gif_module The ngx_http_empty_gif_module module emits single-pixel transparent GIF. Example Configuration location = /_.gif { empty_gif; } Directives Syntax: empty_gif; Default: — Context: location Turns on module processing in a su

nginx.org

 

empty_gif 지시자

  • 주변 위치에서 모듈 처리를 켬
  • 문맥 : location
  • 사용 문법
      # 문법
      empty_gif;

 

 

empty_gif 예제 구성

  • 파일이 없는 경우 단일 픽셀 투명 GIF 전송할 수 있도록 설정
      location = /my_img {
        access_log off;
        empty_gif;
      }

 

 

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

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
ngx_http_addition_module 모듈  (0) 2023.09.21
ngx_http_access_module 모듈  (0) 2023.09.20
 

Module ngx_http_addition_module

Module ngx_http_addition_module The ngx_http_addition_module module is a filter that adds text before and after a response. This module is not built by default, it should be enabled with the --with-http_addition_module configuration parameter. Example Conf

nginx.org

 

  • ngx_http_addition_module 모듈은 응답 전후에 텍스트를 추가하는 필터
  • ngx_http_addition_module 모듈은 기본적으로 빌드되지 않으며 --with-http_addition_module 구성 매개변수를 사용하여 사용하도록 설정

  • 구성 예시
      location / {
          add_before_body /before_action;
          add_after_body  /after_action;
      }

 

add_before_body 지시자

  • 지정된 하위 요청을 처리한 결과 반환된 텍스트를 응답 본문 앞에 추가
  • 매개변수로 빈 문자열("")을 사용하면 이전 구성 수준(previous configuration level)에서 상속된 추가를 취소할 수 있음

  • 문맥 : http, server, location
  • 사용 문법
      # 문법
      add_before_body uri;

 

 

add_after_body 지시자

  • 응답 본문 뒤에 지정된 하위 요청을 처리한 결과로 반환된 텍스트를 추가
  • 매개변수로 빈 문자열("")을 사용하면 이전 구성 수준(previous configuration level)에서 상속된 추가를 취소함

  • 문맥 : http, server, location
  • 사용 문법
      # 문법
      add_before_body uri;

 

addition_types 지시자

  • "text/html" 외에 지정된 MIME 유형의 응답에 텍스트를 추가할 수 있음
  • 특수 값 "*"는 모든 MIME 유형(0.8.29)과 일치

  • 문맥 : http, server, location, limit_except
  • 사용 문법
      # 문법
      addition_types mime-type ...;
  • 사용 예시
      # 사용 예시
      addition_types text/html;

 

 

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

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
ngx_http_empty_gif_module 모듈  (0) 2023.09.21
ngx_http_access_module 모듈  (0) 2023.09.20
 

Module ngx_http_access_module

Module ngx_http_access_module The ngx_http_access_module module allows limiting access to certain client addresses. Access can also be limited by password, by the result of subrequest, or by JWT. Simultaneous limitation of access by address and by password

nginx.org

 

  • ngx_http_access_module 모듈을 사용하면 특정 클라이언트 주소에 대한 액세스를 제한할 수 있음
  • password, result of subrequest 또는 JWT에 의해 액세스를 제한할 수도 있음
  • address와 password에 의한 동시 접근 제한(Simultaneous limitation of access)은 satisfy 지시어로 제어

  • 구성 예시
    location / {
        deny  192.168.1.1;
        allow 192.168.1.0/24;
        allow 10.1.1.0/16;
        allow 2001:0db8::/32;
        deny  all;
    }
  • rules은 첫 번째 일치 항목이 발견될 때까지 순차적으로 확인
  • 주소 192.168.1.1을 제외한 IPv4 네트워크 10.1.1.0/16 및 192.168.1.0/24와 IPv6 네트워크 2001:0db8::/32에 대해서만 액세스가 허용
  • 규칙이 많은 경우 ngx_http_geo_module 모듈 변수를 사용하는 것이 좋음

 

 

allow 지시자

  • 지정된 네트워크 또는 주소에 대한 액세스를 허용
  • 특수 값인 unix:(1.5.1)를 지정하면 모든 UNIX 도메인 소켓에 대한 액세스를 허용

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

 

 

deny 지시자

  • 지정된 네트워크 또는 주소에 대한 액세스를 거부
  • 특수 값인 unix:(1.5.1)를 지정하면 모든 UNIX 도메인 소켓에 대한 액세스를 거부

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

 

 

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

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
ngx_http_empty_gif_module 모듈  (0) 2023.09.21
ngx_http_addition_module 모듈  (0) 2023.09.21
  • OBS Studio는 장면을 무한대로 만들 수 있음
  • 한 장면에 다양한 소스를 넣을 수 있음
  • 하드 디스크에 저장되어 있는 동영상 파일을 1개 넣어 OBS Studio 실행

 

  • 소스 목록 창에서 마우스 우클릭 하거나 < + > 표시를 누르면 추가 목록이 출력

 

  • "미디어 소스"를 클릭

 

  • 동영상 파일 위치를 찾아줌 → 아래 옵션 설정
    1. 반복 재생 여부
    2. 소스가 활성화될 때 재생을 다시 시작
    3. 가능한 경우 하드웨어 디코딩 사용
    4. 재생이 끝나면 아무것도 표시하지 않기
    5. 비활성화 상태일 때 파일 닫기 등

 

  • 영상을 불러왔는데 화면 비율이 맞지 않으면 크기 조절 가능
    • 미리 보기 화면창에서 우 클릭을 하고 출력 크기 조정 (소스 크기)를 클릭하면 화면 비율에 맞도록 조절 가능

    • 조절 전(출력 크기가 작음)


    • 조절 → 출력 크기 조정(소스 크기)


    • 조절 후

 

참고 자료

'Media(미디어) > OBS' 카테고리의 다른 글

OBS 송출 설정  (0) 2023.09.18
OBS(Open Broadcaster Software)란  (0) 2023.09.18

+ Recent posts