Module ngx_http_v2_module

Module ngx_http_v2_module The ngx_http_v2_module module (1.9.5) provides support for HTTP/2. This module is not built by default, it should be enabled with the --with-http_v2_module configuration parameter. Known Issues Before version 1.9.14, buffering of

nginx.org

 

  • ngx_http_v2_module 모듈(1.9.5)은 HTTP/2를 지원
  • ngx_http_v2_module 모듈은 기본적으로 빌드되지 않으며, --with-http_v2_module 구성 매개변수를 사용하여 활성화

 

  • TLS를 통해 HTTP/2 연결을 수락하려면 OpenSSL 버전 1.0.2부터 제공되는 “ALPN(Application-Layer Protocol Negotiation)” TLS 확장 지원이 필요
  • ssl_prefer_server_ciphers 지시어가 on 값으로 설정된 경우 암호는 RFC 9113의 부록 A 블랙리스트(black list)를 준수하고 클라이언트에서 지원하도록 구성
  • RFC 9113의 부록 A : https://datatracker.ietf.org/doc/html/rfc9113#appendix-A

 

  • Nginx 1.9.14 버전 이전에는 proxy_request_buffering, fastcgi_request_buffering, uwsgi_request_buffering 및 scgi_request_buffering 지시어 값에 관계없이 client request body 버퍼링(Buffering)을 비활성화할 수 없음
  • Nginx 1.19.1 이전에는 HTTP/2 연결(connections) 종료를 제어하는 데, lingering_close 메커니즘 사용 X

 

ngx_http_v2_module 구성 예

server {
    listen 443 ssl;

    http2 on;

    ssl_certificate server.crt;
    ssl_certificate_key server.key;
}

 

 

http2 지시자

  • HTTP/2 프로토콜을 활성화
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2 on | off;
  • 기본 사용 예시
    http2 off;

 

 

http2_body_preread_size 지시자

  • 요청(request)을 처리 시작하기 전에 요청 본문(request body)이 저장될 수 있는 각 요청(request)당 버퍼(buffer)의 크기를 설정
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_body_preread_size size;
  • 기본 사용 예시
    http2_body_preread_size 64k;

 

 

http2_chunk_size 지시자

  • 응답 본문(response body)이 슬라이스(slice)되는 청크(chunks)의 최대 크기를 설정 
  • 슬라이스(slice)되는 청크(chunks) 값이 너무 낮으면 오버헤드가 증가 
  • 슬라이스(slice)되는 청크(chunks) 값이 너무 높으면 HOL 블로킹으로 인해 우선 순위가 손상
     
  • 문맥: http, server, location
  • 사용 문법
    # 문법
    http2_chunk_size size;
  • 기본 사용 예시
    http2_chunk_size 8k;

 

 

http2_max_concurrent_streams 지시자

  • 연결(connection)에서 최대 동시 HTTP/2 스트림(concurrent HTTP/2 streams) 수를 설정
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_max_concurrent_streams number;
  • 기본 사용 예시
    http2_max_concurrent_streams 128;

 

 

http2_recv_buffer_size 지시자

  • 작업자(worker)당 입력 버퍼(input buffer)의 크기를 설정
     
  • 문맥: http
  • 사용 문법
    # 문법
    http2_recv_buffer_size size;
  • 기본 사용 예시
    http2_recv_buffer_size 256k;

 

 

ngx_http_v2_module 모듈의 내장 변수 → $http2

  • negotiated protocol identifier(협상된 프로토콜 식별자)
    1. TLS를 통한 HTTP/2의 경우 “h2”
    2. 투명 텍스트 TCP(cleartext TCP)를 통한 HTTP/2의 경우 “h2c”
    3. 그렇지 않으면 빈 문자열

 

 

http2_max_concurrent_pushes 지시자

  • http2_max_concurrent_pushes 지시어는 버전 1.25.1부터 사용 X
  • 연결(connection)에서 동시 푸시 요청(concurrent push requests )의 최대 수(maximum number)를 제한
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_max_concurrent_pushes number;
  • 기본 사용 예시
    http2_max_concurrent_pushes 10;

 

 

http2_push 지시자

  • http2_push 지시어는 버전 1.25.1부터 사용 X
  • original 요청에 대한 응답과 함께 지정된 URI로 요청을 선제적(pre-emptively)으로 전송(푸시)
  • 예) 절대 경로(absolute path)를 가진 상대 URI(relative URI)만 처리 : http2_push /static/css/main.css;
     
  • URI 값에는 변수가 포함 가능
  • 동일한 설정 수준에서 여러 개의 http2_push 지시문을 지정 가능 
  • http2_push 지시어의 off 매개변수는 이전 configuration에서 상속된 http2_push 지시어의 효과를 취소함
     
  • 문맥: http, server, location
  • 사용 문법
    # 문법
    http2_push uri | off;
  • 기본 사용 예시
    http2_push off;

 

 

http2_push_preload 지시자

  • http2_push_preload 지시어는 버전 1.25.1부터 사용 X
  • Link 응답 헤더 필드(response header field)에 지정된 프리로드 링크(preload links)를 푸시 요청(push requests)으로 자동 변환
     
  • 문맥: http, server, location
  • 사용 문법
    # 문법
    http2_push_preload on | off;
  • 기본 사용 예시
    http2_push_preload off;

 

 

http2_idle_timeout 지시자

  • http2_idle_timeout 지시어는 버전 1.19.7부터 사용 X → http2_idle_timeout 대신 keepalive_timeout를 사용
  • 연결(connection)이 닫히는 비활성 시간 제한(timeout of inactivity)을 설정
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_idle_timeout time;
  • 기본 사용 예시
    http2_idle_timeout 3m;

 

 

http2_max_field_size 지시자

  • http2_max_field_size 지시어는 버전 1.19.7부터 사용 X → http2_max_field_size 대신 large_client_header_buffers 사용
  • HPACK 압축 요청 헤더 필드(HPACK-compressed request header)의 최대 크기를 제한 → 최대 크기 제한은 이름과 값 모두에 동일하게 적용 
  • 허프만 인코딩(Huffman encoding)이 적용되면 압축 해제된 이름 및 값 문자열의 실제 크기가 더 커질 수 있음
  • 대부분의 요청은 http2_max_field_size 기본 제한 크기로 충분
  • HPACK 압축 : https://datatracker.ietf.org/doc/html/rfc7541
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_max_field_size size;
  • 기본 사용 예시
    http2_max_field_size 4k;

 

 

http2_max_header_size 지시자

  • http2_max_header_size 지시어는 1.19.7부터 사용 X → http2_max_header_size 대신 large_client_header_buffers 사용
  • HPACK 압축 해제(HPACK decompression) 후 전체 요청 헤더 목록(entire request header list)의 최대 크기를 제한 
  • 대부분의 요청(requests)에서는 기본 제한으로 충분
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_max_header_size size;
  • 기본 사용 예시
    http2_max_header_size 16k;

 

 

http2_max_requests 지시자

  • http2_max_requests 지시어는 버전 1.19.7부터 사용 X → http2_max_requests 대신 keepalive_requests 사용
  • 하나의 HTTP/2 연결(HTTP/2 connection)을 통해 처리할 수 있는 최대 요청 수(push requests 포함)를 설정하며, 그 이후 다음 클라이언트 요청(next client request)이 있을 때 연결이 닫히고 새 연결을 진행
  • 주기적으로 연결을 닫는 것은 연결별 메모리 할당(per-connection memory allocations)을 확보하기 위해 필요 
  • 최대 요청 수를 너무 많이 사용하면 메모리를 과도하게 사용할 수 있으므로 권장 X
     
  • 문맥: http, server
  • 사용 문법
    # 문법
    http2_max_requests number;
  • 기본 사용 예시
    http2_max_requests 1000;

 

 

http2_recv_timeout  지시자

  • http2_recv_timeout 지시어는 1.19.7부터 사용 X → http2_recv_timeout  대신 client_header_timeout를 사용
  • 클라이언트로부터 추가로 전달될 데이터를 기대하는 시간 제한(timeout) 설정한 후 연결을 닫음.
     
  • 문맥: http, server
  • 사용 문법 
  • # 문법 http2_recv_timeout time;
  • 기본 사용 예시
    http2_recv_timeout 30s;

 

 

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

ngx_http_auth_basic_module 모듈  (1) 2024.12.15
ngx_http_autoindex_module 모듈  (0) 2024.12.15
ngx_http_dav_module 모듈  (1) 2024.12.11
ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_mp4_module 모듈  (0) 2023.09.24
 

Module ngx_http_auth_basic_module

Module ngx_http_auth_basic_module The ngx_http_auth_basic_module module allows limiting access to resources by validating the user name and password using the “HTTP Basic Authentication” protocol. Access can also be limited by address, by the result of

nginx.org

 

  • ngx_http_auth_basic_module 모듈은 "HTTP Basic Authentication" 프로토콜을 사용하여 user name과 password를 검증함으로써 리소스에 대한 접근을 제한 가능
  • 주소(address), subrequest의 결과 또는 JWT에 의해 액세스를 제한
  • 주소(address)와 비밀번호(password)에 의한 접근 제한을 동시에 적용하려면 satisfy 지시어로 제어

auth_basic 지시자

  • “HTTP Basic Authentication” 프로토콜을 사용하여 user name과 password 의 유효성 검사를 활성화 
  • 지정된 매개변수는 영역(realm)으로 사용
  • off는 configuration level에서 상속된 auth_basic 지시어의 효과를 취소

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

 

auth_basic_user_file 지시자

  • user name과 password를 저장하는 파일을 지정
  • 파일 이름에는 변수를 포함 가능
    # comment
    name1:password1
    name2:password2:comment
    name3:password3
     
  • 아래와 같은 password 유형이 지원
    1. crypt() 함수로 암호화된 비밀번호 → Apache HTTP Server의 htpasswd나 openssl passwd 명령어로 생성 가능
    2. Apache 버전의 MD5 기반 비밀번호 알고리즘(apr1)으로 해시된 비밀번호 → Apache HTTP Server의 htpasswd openssl passwd 명령어로 생성 가능
    3. RFC 2307에 설명된 대로 “{scheme}data” 구문으로 지정 → 구현된 스키마에는 PLAIN, SHA(SHA-1 hashing, 추천 X) 및 SSHA(salted SHA-1 hashing, 일부 소프트웨어 패키지, 특히 OpenLDAP 및 Dovecot에서 사용)
 
  • 문맥 : http, server, location, limit_except
  • 사용문법
    ## 기본 설정
    auth_basic_user_file file;

 

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

ngx_http_v2_module 모듈  (0) 2025.01.18
ngx_http_autoindex_module 모듈  (0) 2024.12.15
ngx_http_dav_module 모듈  (1) 2024.12.11
ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_mp4_module 모듈  (0) 2023.09.24
 

Module ngx_http_autoindex_module

Module ngx_http_autoindex_module The ngx_http_autoindex_module module processes requests ending with the slash character (‘/’) and produces a directory listing. Usually a request is passed to the ngx_http_autoindex_module module when the ngx_http_index

nginx.org

 

  • ngx_http_autoindex_module 모듈은 슬래시 문자('/')로 끝나는 요청을 처리하고 디렉토리 목록을 생성
  • 요청은 ngx_http_index_module 모듈이 인덱스 파일을 찾을 수 없을 때, ngx_http_autoindex_module 모듈로 전달

 

autoindex 지시자

  • 디렉터리 목록(listing) 출력을 활성화 또는 비활성화

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

 

autoindex_exact_size 지시자

  • HTML 형식의 경우 디렉토리 목록에 정확한 파일 크기를 출력할지 아니면 킬로바이트, 메가바이트, 기가바이트로 반올림하여 출력할지 지정

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

 

autoindex_format 지시자

  • 디렉토리 목록의 형식을 설정
  • JSONP 형식이 사용될 때, 콜백 함수(callback function)의 이름은 콜백 요청 인수(callback request argument)로 설정
  • 만약 인수가 없거나 값이 비어 있으면 JSON 형식이 사용
  • XML 출력은 ngx_http_xslt_module 모듈을 사용하여 변환 가능

     
  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    autoindex_format html | xml | json | jsonp;
  • 사용 예시
    ## 기본 설정
    autoindex_format html;

 

autoindex_localtime 지시자

  • HTML 형식에서는 디렉터리 목록(listing)의 시간이 로컬 시간대( local time zone)또는 UTC로 출력될지 여부를 지정
     
  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    autoindex_localtime on | off;
 
  • 사용 예시
    ## 기본 설정
    autoindex_localtime off;

 

 

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

ngx_http_v2_module 모듈  (0) 2025.01.18
ngx_http_auth_basic_module 모듈  (1) 2024.12.15
ngx_http_dav_module 모듈  (1) 2024.12.11
ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_mp4_module 모듈  (0) 2023.09.24
 

Module ngx_http_dav_module

Module ngx_http_dav_module The ngx_http_dav_module module is intended for file management automation via the WebDAV protocol. The module processes HTTP and WebDAV methods PUT, DELETE, MKCOL, COPY, and MOVE. This module is not built by default, it should be

nginx.org

 

  • ngx_http_dav_module 모듈은 WebDAV 프로토콜을 통한 파일 관리 자동화를 위한 모듈
  • HTTP 및 WebDAV 메서드 PUT, DELETE, MKCOL, COPY, MOVE를 처리
  • 기본적으로 빌드되지 않으며, --with-http_dav_module 구성 매개변수를 사용하여 활성화 필요

 

create_full_put_path 지시자

  • WebDAV 사양은 이미 존재하는 디렉토리에만 파일을 생성 가능 
  • create_full_put_path 지시자를 통해 필요한 모든 중간 디렉토리를 생성 가능

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

 

dav_access 지시자

  • 새로 만든 파일 및 디렉터리에 대한 액세스 권한을 설정 → dav_access user:rw group:rw all:r;
  • 그룹 또는 모든 액세스 권한이 지정되면 사용자 권한은 생략 가능 → dav_access group:rw all:r;

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    dav_access users:permissions ...;
  • 사용 예시
    ## 기본 설정
    dav_access user:rw;

 

dav_methods 지시자

  • 지정된 HTTP 및 WebDAV 메서드를 허용
  • 매개변수 off는 ngx_http_dav 모듈에서 처리하는 모든 메서드를 거부 
  • ngx_http_dav 모듈 지원되는 메서드 → PUT, DELETE, MKCOL, COPY, MOVE

  • PUT 메서드로 업로드된 파일은 먼저 임시 파일에 기록된 다음 파일 이름이 변경됨 
  • 버전 0.8.9부터는 PUT 메서드로 임시 파일과 영구 저장소를 서로 다른 파일 시스템에 등록 가능
    1. 서로 다른 파일 시스템에 등록은 이름 변경 작업 대신 두 파일 시스템에 걸쳐 복사된다는 의미 
    2. 특정 위치에 대해 저장된 파일과 client_body_temp_path 지시어로 설정한 임시 파일이 있는 디렉토리를 모두 같은 파일 시스템에 저장하는 것을 추천
  • PUT 방식으로 파일을 만들 때 "Date" 헤더 필드에 수정 날짜(modification date)를 전달하여 수정 날짜를 지정 가능

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

 

min_delete_depth 지시자

    • 요청 경로(request path)의 요소 수(number of elements)가 지정된 수보다 작지 않은 경우 DELETE 메서드가 파일을 제거 가능
    • min_delete_depth 지시자 예시
      ## min_delete_depth 지시자 설정
      min_delete_depth 4;
      
      ## 요청 시 파일 제거 허용
      /users/00/00/name
      /users/00/00/name/pic.jpg
      /users/00/00/page.html
      
      ## 요청 시 파일 제제거를 거부
      /users/00/00
  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    min_delete_depth number;
  • 사용 예시
    ## 기본 설정
    min_delete_depth 0;

 

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

ngx_http_auth_basic_module 모듈  (1) 2024.12.15
ngx_http_autoindex_module 모듈  (0) 2024.12.15
ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_mp4_module 모듈  (0) 2023.09.24
ngx_http_referer_module 모듈  (0) 2023.09.23
 

Module ngx_http_hls_module

Module ngx_http_hls_module The ngx_http_hls_module module provides HTTP Live Streaming (HLS) server-side support for MP4 and MOV media files. Such files typically have the .mp4, .m4v, .m4a, .mov, or .qt filename extensions. The module supports H.264 video

nginx.org

 

  • ngx_http_hls_module 모듈은 MP4 및 MOV 미디어 파일에 대한 HTTP 라이브 스트리밍(HLS) 서버 측 지원을 제공
  • 파일의 파일 확장자는 일반적으로 .mp4, .m4v, .m4a, .mov, .qt
  • ngx_http_hls_module 모듈은 H.264 비디오 코덱, AAC 및 MP3 오디오 코덱을 지원

  • 각 미디어 파일에 대해 두 개의 URI가 지원
    1. 파일 이름 확장자가 .m3u8인 재생 목록 URI (URI는 아래 선택적 인수를 사용 가능)
      • start 및 end는 재생 목록 경계(playlist boundaries)를 초 단위로 정의
      • offset은 초기 재생 위치를 초 단위의 시간 오프셋(time offset)으로 이동
      • 양수 값은 재생 목록의 시작부터 시간 오프셋(offset)을 설정
      • 음수 값은 재생 목록의 마지막 조각 끝에서 시간 오프셋(offset)을 설정
      • len은 조각 길이를 초 단위로 정의
    2. 파일 이름 확장자가 ".ts"인 조각 URI (URI는 아래 선택적 인수를 사용 가능)
      • start 및 end는 조각 경계(fragment boundaries)를 초 단위로 정의

  • 구성 예시
    location / {
        hls;
        hls_fragment            5s;
        hls_buffers             10 10m;
        hls_mp4_buffer_size     1m;
        hls_mp4_max_buffer_size 5m;
        root /var/video/;
    }

 

  • 위 구성을 사용하면 "/var/video/test.mp4" 파일에 대해 다음 URI가 지원
    http://hls.example.com/test.mp4.m3u8?offset=1.000&start=1.000&end=2.200
    http://hls.example.com/test.mp4.m3u8?len=8.000
    http://hls.example.com/test.mp4.ts?start=1.000&end=2.200

 

hls 지시자

  • HLS 스트리밍 설정

  • 문맥 : location
  • 사용 문법
    ## 문법
    hls;

 

hls_buffers 지시자

  • 데이터 프레임 읽기 및 쓰기에 사용되는 버퍼의 최대 수와 크기를 설정

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    hls_buffers number size;
  • 사용 예시
    ## 사용 예시(기본 설정)
    hls_buffers 8 2m;

 

hls_forward_args 지시자

  • 재생 목록 요청(playlist request)의 인수(arguments)를 URI의 조각(fragments)에 추가
  • 조각(fragments)을 요청하는 순간에 클라이언트 인증을 수행하거나 ngx_http_secure_link_module 모듈로 HLS 스트림을 보호할 때 유용하게 사용 가능
  • 예시) 클라이언트가 http://example.com/hls/test.mp4.m3u8?a=1&b=2 재생 목록을 요청하는 경우, 인수가 시작되고 끝나는 부분 뒤에 인자 a=1 및 b=2가 조각의 URI에 추가
    #EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:15
    #EXT-X-PLAYLIST-TYPE:VOD
    
    #EXTINF:9.333,
    test.mp4.ts?start=0.000&end=9.333&a=1&b=2
    #EXTINF:7.167,
    test.mp4.ts?start=9.333&end=16.500&a=1&b=2
    #EXTINF:5.416,
    test.mp4.ts?start=16.500&end=21.916&a=1&b=2
    #EXTINF:5.500,
    test.mp4.ts?start=21.916&end=27.416&a=1&b=2
    #EXTINF:15.167,
    test.mp4.ts?start=27.416&end=42.583&a=1&b=2
    #EXTINF:9.626,
    test.mp4.ts?start=42.583&end=52.209&a=1&b=2 
    
    #EXT-X-ENDLIST

 

  • HLS 스트림이 ngx_http_secure_link_module 모듈로 보호되는 경우, 조각을 요청할 때 오류가 발생할 수 있으므로 secure_link_md5 표현식에 $uri를 사용해서는 안 됨
  • $uri 대신 Base URI를 사용해야 함(예시에서는 $hls_uri)
    http {
        ... 
        map $uri $hls_uri {
            ~^(?<base_uri>.*).m3u8$ $base_uri;
            ~^(?<base_uri>.*).ts$   $base_uri;
            default                 $uri;
        }
        
        server {
            ...
            location /hls/ {
                hls;
                hls_forward_args on; 
                alias /var/videos/;
                secure_link $arg_md5,$arg_expires;
                secure_link_md5 "$secure_link_expires$hls_uri$remote_addr secret";
                
                if ($secure_link = "") {
                    return 403;
                }
                
                if ($secure_link = "0") {
                    return 410;
                }
            }
        }
    }

 

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

 

hls_fragment 지시자

  • len 인수 없이 요청된 재생 목록 URI의 기본 조각 길이를 정의

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    hls_fragment time;
  • 사용 예시
    ## 사용 예시(기본 설정)
    hls_fragment 5s;

 

hls_mp4_buffer_size 지시자

  • MP4 및 MOV 파일 처리에 사용되는 버퍼의 초기 크기를 설정

  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    hls_mp4_buffer_size size;
  • 사용 예시
    ## 사용 예시(기본 설정)
    hls_mp4_buffer_size 512k

 

hls_mp4_max_buffer_size 지시자

  • 메타데이터(metadata)를 처리하는 동안 더 큰 버퍼가 필요할 수 있음
  • 버퍼의 크기가 지정된 크기를 초과할 수 없으며, 그렇지 않으면 nginx에서 서버 오류 500(내부 서버 오류)을 반환

  • 발생 에러
    "/some/movie/file.mp4" mp4 moov atom is too large:
    12583268, you may want to increase hls_mp4_max_buffer_size
     
  • 문맥 : http, server, location
  • 사용 문법
    ## 문법
    hls_mp4_max_buffer_size size;
  • 사용 예시
    ## 사용 예시(기본 설정)
    hls_mp4_max_buffer_size 10m;

 

 

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

ngx_http_autoindex_module 모듈  (0) 2024.12.15
ngx_http_dav_module 모듈  (1) 2024.12.11
ngx_http_mp4_module 모듈  (0) 2023.09.24
ngx_http_referer_module 모듈  (0) 2023.09.23
ngx_http_secure_link_module 모듈  (0) 2023.09.23
 

Module ngx_http_mp4_module

Module ngx_http_mp4_module The ngx_http_mp4_module module provides pseudo-streaming server-side support for MP4 files. Such files typically have the .mp4, .m4v, or .m4a filename extensions. Pseudo-streaming works in alliance with a compatible media player.

nginx.org

 

  • ngx_http_mp4_module 모듈은 MP4 파일에 대한 pseudo-streaming 지원
  • 일반적으로 .mp4, .m4v또는 .m4a파일 이름 확장자가 있음
  • pseudo-streaming은 호환되는 미디어 플레이어와 함께 작동함
  • 플레이어는 쿼리 문자열 인수(초 단위로 지정)에 지정된 시작 시간과 함께 서버에 HTTP 요청을 보냄
  • start는 시작시간을 요청된 시간과 일치하도록 스트림으로 응답
  • 언제든지 무작위 검색을 수행하거나 타임라인 중간에 재생을 시작 가능
  • 재생을 시작하려면 플레이어가 먼저 메타데이터를 읽어야 함 → start=0 인수와 함께 특수 요청을 전송하여 수행

  • start 사용 예시
    http://example.com/elephants_dream.mp4?start=238.88

 

  • ngx_http_mp4_module 모듈 end은 재생의 끝점을 설정하는 HTTP 요청의 인수도 지원
  • start가 0이 아니거나 인수가 있는 일치 요청의 end 경우 nginx는 파일에서 메타데이터를 읽고 요청된 시간 범위로 스트림을 준비하여 클라이언트에 보냄 → 오버헤드를 발생
  • start 인수가 키가 아닌 비디오 프레임을 가리키는 경우 해당 비디오의 시작 부분이 깨짐 → 문제를 해결하기 위해 포인트 앞의 키 프레임과 그 사이의 모든 중간 프레임을 비디오 앞에 추가 가능
  • start이 프레임은 편집 목록(1.21.4)을 사용하여 재생에서 숨김
  • 일치하는 요청에 start 및 end 인수가 포함되지 않은 경우 오버헤드가 없으며 파일은 단순히 정적 리소스로 전송

  • 인수 end와 함께 start를 지정하거나 별도로 지정 가능
    http://example.com/elephants_dream.mp4?start=238.88&end=555.55

 

※ 메타데이터

  • 검색을 지원하기 위해 H.264 기반 포맷은 메타데이터를 "moov atom"에 저장 → 전체 파일에 대한 인덱스 정보를 저장하는 파일 일부
  • 재생을 시작하려면 플레이어가 먼저 메타데이터를 읽어야함
  • 많은 인코딩 소프트웨어는 파일 끝에 메타데이터를 삽입함 → 플레이어는 재생을 시작하기 전에 전체 파일을 다운로드해야 하기 때문에 pseudo-streaming에는 차선의 선택
  • 메타데이터가 파일 시작 부분에 있으면 nginx가 파일 내용을 다시 보내기 시작하는 것으로 충분
  • 메타데이터가 파일 끝에 있는 경우 nginx는 전체 파일을 읽고 미디어 데이터보다 메타데이터가 먼저 오도록 새 스트림을 준비해야 함
  • CPU, 메모리 및 디스크 I/O 오버헤드가 수반되므로 nginx가 이러한 모든 요청에 대해 이 작업을 수행하도록 하기보다는 pseudo-streaming을 위한 원본 파일을 미리 준비하는 것이 좋음

 

ngx_http_mp4_module 모듈 지시문

  • 일부 플레이어는 바이트 범위 요청도 지원하므로 ngx_http_mp4_module 모듈이 필요하지 않음
  • --with-http_mp4_module 모듈은 기본적으로 빌드되지 않으며 구성 매개변수로 활성화해야 함
  • 타사 mp4 모듈을 이전에 사용한 경우 비활성화해야 함
  • FLV 파일에 대한 유사한 의사 스트리밍 지원은 ngx_http_flv_module 모듈에서 제공함

  • 구성 예
    location /video/ {
         mp4;
         mp4_buffer_size       1m;
         mp4_max_buffer_size   5m;
         mp4_limit_rate        on;
         mp4_limit_rate_after  30s;
    }

 

mp4 지시어

  • mp4 모듈 처리를 킴

  • 문맥 : location
  • 사용 문법과 사용 예시
    # 문법 : mp4;
    mp4;

 

mp4_buffer_size size 지시어

  • mp4 파일 처리에 사용되는 버퍼의 초기 크기를 설정

  • 문맥 : http, server, location
  • 사용 문법
    # 문법
    mp4_buffer_size size;
  • 사용 예시
    # 사용 예시
    mp4_buffer_size 512K;

 

mp4_max_buffer_size 지시자

  • 메타데이터 처리 중에 더 큰 버퍼가 필요한 경우가 있음
  • 메타데이터 처리 중에 버퍼 크기는 지정된 크기를 초과할 수 없음
  • 버퍼 크기보다 초과하는 경우, nginx가 500(내부 서버 오류) 서버 오류를 반환하고 아래 메시지 출력
    "/some/movie/file.mp4" mp4 moov atom is too large:
    12583268, you may want to increase mp4_max_buffer_size

 

  • 문맥: http, server, location
  • 사용 문법
    # 문법
    mp4_max_buffer_size size;
  • 사용 예시
    # 사용 예시
    mp4_max_buffer_size 10M;

 

※ mp4_max_buffer_size가 작아 500 에러 발생 예시

  • 500 에러 발생 화면 (참고 URL : http://도메인/a.mp4?start=100)

 

  • 500 에러 발생 error 로그
    날짜 시간 [error] 24042404: *94087966 "a.mp4" mp4 moov atom is too large:5448131, 
    you may want to increase mp4_max_buffer_size, client: 111.111.111.111,
    ### 생략

 

  • 500 에러 발생 시 mp4_max_buffer_size 값을 올려주면 해결할 수 있음

 

 

mp4_limit_rate 지시자

  • 클라이언트에 대한 응답 전송 속도를 제한
  • 전송 속도는 제공되는 MP4 파일의 평균 비트 전송률에 따라 제한

  • mp4_limit_rate 사용 값
    1. factor → 전송률을 계산하려면 비트 전송률(bitrate)에 지정된 factor를 곱함
    2. on → on을 설정하면 속도 제한을 활성화하며, factor는 1.1에 해당
    3. off → 속도 제한을 비활성화

  • limit는 요청별로 설정이 됨 → 클라이언트가 동시에 두 개의 연결을 열면 전체 속도는 지정된 제한의 두 배가됨

  • 문맥: http, server, location
  • 사용 문법과 기본 사용 예시
    # 문법
    mp4_limit_rate on | off | factor;
    
    # 사용 예시
    mp4_limit_rate off;

 

 

mp4_limit_rate_after 지시자

  • 초기 미디어 데이터 양(재생 시간으로 측정)을 설정. 이후 클라이언트로의 응답 전송 속도가 제한

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

 

 

mp4_start_key_frame 지시자

  • 출력 비디오가 항상 키 비디오 프레임으로 시작하도록 함
  • start 인수가 키 프레임을 가리키지 않으면, 초기 프레임은 mp4 편집 목록을 사용하여 숨겨짐.
  • 편집 목록은 Firefox에서 부분적으로 지원
  • 편집 목록은 Chrome, Safari, QuickTime 및 ffmpeg와 같은 주요 플레이어 및 브라우저에서 지원됨

  • 문맥: http, server, location
  • 해당 지시자는 nginx 1.21.4 버전 이후부터 사용 가능
  • 사용 문법
    # 문법
    mp4_start_key_frame on | off;
  • 기본 사용 예시
    mp4_start_key_frame off;

 

 

참고 자료

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

ngx_http_dav_module 모듈  (1) 2024.12.11
ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_referer_module 모듈  (0) 2023.09.23
ngx_http_secure_link_module 모듈  (0) 2023.09.23
ngx_http_realip_module 모듈  (0) 2023.09.23
 

Module ngx_http_referer_module

Module ngx_http_referer_module The ngx_http_referer_module module is used to block access to a site for requests with invalid values in the “Referer” header field. It should be kept in mind that fabricating a request with an appropriate “Referer” f

nginx.org

 

  • ngx_http_referer_module 모듈은 "Referer" 헤더 필드에 잘못된 값을 가진 요청에 대한 사이트 액세스를 차단하는 데 사용
  • 적절한 "Referer" 필드 값을 사용하여 요청을 조작하는 것은 매우 쉬움
  • ngx_http_referer_module 모듈의 목적은 요청을 완전히 차단하는 것이 아니라 일반 브라우저에서 전송되는 요청의 대량 흐름을 차단하는 것을 염두에 두어 사용
  • 일반 브라우저는 유효한 요청에 대해서도 "Referer" 필드를 보내지 않을 수 있다는 점도 고려

  • 사용 예시
    valid_referers none blocked server_names
                   *.example.com example.* www.example.org/galleries/
                   ~\.google\.;
    
    if ($invalid_referer) {
        return 403;
    }

 

 

referer_hash_bucket_size 지시자

  • 유효한 레퍼러(valid referers) 해시 테이블(hash tables)의 버킷 크기(bucket size)를 설정
  • 해시 테이블(hash tables) 설정에 대한 자세한 내용은 옆 URL 확인  http://nginx.org/en/docs/hash.html

  • 문맥 : server, location
  • 사용 문법
    ## 문법
    referer_hash_bucket_size size;
  • 사용 예시
    ## 기본 설정
    referer_hash_bucket_size 64;

 

 

referer_hash_max_size 지시자

  • 유효한 참조(valid referers) 해시 테이블(hash tables)의 최대 크기를 설정
  • 해시 테이블(hash tables) 설정에 대한 자세한 내용은 옆 URL 확인  http://nginx.org/en/docs/hash.html

  • 문맥 : server, location
  • 사용 문법
    ## 문법
    referer_hash_max_size size;
  • 사용 예시
    ## 기본 설정
    referer_hash_max_size 2048;

 

 

valid_referers 지시자

  • embedded(내장된) $invalid_referer 변수가 빈 문자열(empty string)로 설정되도록 하는 "Referer" 요청 헤더 필드 값(request header field values을 지정
  • "Referer" 요청 헤더 필드 값(request header field value)이 유효하지 않은 것으로 간주되면 $invalid_referer 변수가 "1"로 설정
  • 일치 검색(Search for a match)은 대소문자(case-insensitive)를 구분하지 않음

  • 문맥 : server, location
  • 사용 문법
    ## 문법
    valid_referers none | blocked | server_names | string ...;

 

 

valid_referers 지시자의 매개변수

1. none

  • 요청 헤더(request header) 안에 "Referer" 필드가 없는 경우

 

2. blocked

  • 요청 헤더(request header)에 "Referer" 필드가 있지만, 방화벽(firewall) 또는 프록시 서버(proxy server)에 의해 해당 값이 삭제되는 경우
  • 값은 "http://" 또는 "https://"로 시작하지 않는 문자열

 

3. server_names

  • 요청 헤더 필드(request header field)에 서버 이름(server names) 중 하나가 포함된 경우

 

4. arbitrary string

  • 임의의 문자열(arbitrary string)은 서버 이름(server name)과 선택적 URI 접두사(optional URI prefix)를 정의
  • 서버 이름(server name)은 시작 또는 끝에 "*"가 올 수 있음
  • 검사하는 동안 "Referer" 필드에 있는 서버의 포트는 무시됨

 

5. regular expression

  • 정규식(regular expression)의 경우 첫 번째 기호는 "~"여야 함
  • 정규식(regular expression)은 "http://" 또는 "https://" 뒤에 시작하는 텍스트에 대해 일치하는지 확인

 

 

ngx_http_referer_module 모듈의 내장 변수 → $invalid_referer

  • "Referer" 요청 헤더 필드 값(request header field value)이 유효한 것으로 간주되는 경우 빈 문자열, 그렇지 않으면 "1"

 

 

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

ngx_http_hls_module 모듈  (0) 2023.09.24
ngx_http_mp4_module 모듈  (0) 2023.09.24
ngx_http_secure_link_module 모듈  (0) 2023.09.23
ngx_http_realip_module 모듈  (0) 2023.09.23
ngx_http_slice_module 모듈  (0) 2023.09.22
 

Module ngx_http_secure_link_module

Module ngx_http_secure_link_module The ngx_http_secure_link_module module (0.7.18) is used to check authenticity of requested links, protect resources from unauthorized access, and limit link lifetime. The authenticity of a requested link is verified by co

nginx.org

 

  • ngx_http_secure_link_module 모듈 사용 용도
    1. 요청된 링크의 진위를 확인
    2. 무단 액세스로부터 리소스를 보호
    3. 링크 수명을 제한

  • 검사의 상태는 $secure_link 변수에서 사용
  • 요청된 링크의 신뢰성은 요청에 전달된 체크섬 값과 요청에 대해 계산된 값을 비교하여 확인
  • 링크의 수명이 제한되어 있고 시간이 만료된 경우 해당 링크는 오래된 것으로 간주

  • ngx_http_secure_link_module 모듈은 두 가지 대체 작동 모드를 제공
    1. secure_link_secret 지시문에 의해 활성화→ 요청된 링크의 신뢰성을 확인하고 무단 액세스로부터 리소스를 보호하는 데 사용
    2. secure_link 및 secure_link_md5 지시문에 의해 활성화되며 링크 수명을 제한하는 데에도 사용

 

 

secure_link 지시어

  • secure_link 지시어는 링크의 체크섬 값과 수명을 추출할 변수가 있는 문자열을 정의
  • secure_link 지시어는 일반적으로 요청과 연결됨

  • 문맥: http, server, location
  • 사용 문법
    # 문법 : secure_link 표현법
    secure_link expression;

 

  • 문자열에서 추출한 체크섬 값은 secure_link_md5 지시문에서 정의한 표현식의 MD5 해시 값과 비교
    1. 체크섬이 다른 경우 $secure_link 변수는 빈 문자열로 설정
    2. 체크섬이 같으면 링크 수명을 확인

  • 링크의 수명이 제한되어 있고 시간이 만료된 경우에도 $secure_link 변수 설정
    1. 링크의 수명이 제한되어 있고 시간이 만료된 경우 $secure_link 변수는 "0"으로 설정
    2. 그렇지 않은 경우 $secure_link 변수는 "1"로 설정

  • 요청에 전달된 MD5 해시 값은 base64url로 인코딩
    1. 링크의 수명이 제한된 경우 만료 시간은 Epoch(1970년 1월 1일 00:00:00 GMT) 이후 초 단위로 설정
    2. MD5 해시 다음에 표현식에 지정되며 쉼표로 구분
    3. 요청에 전달된 만료 시간은 secure_link_md5 지시문에서 사용하기 위해 $secure_link_expires 변수를 통해 사용 가능
      만료 시간이 지정되지 않은 경우 링크의 수명은 무제한임

 

 

2. secure_link_md5 지시어

  • MD5 해시 값이 계산되고 요청에 전달된 값과 비교되는 식을 정의
  • 식에는 링크(리소스)의 보안 부분과 비밀 요소가 포함되어야함

  • 문맥: http, server, location
  • 사용 문법
    # 문법 : secure_link_md5 표현법
    secure_link_md5 expression;

 

  • 링크의 수명이 제한된 경우 표현식에 $secure_link_expires도 포함되어야함
  • 무단 액세스를 방지하기 위해 식에는 주소 및 브라우저 버전과 같은 클라이언트에 대한 일부 정보가 포함될 수 있음
    location /s/ {
        secure_link $arg_md5,$arg_expires;
        secure_link_md5 "$secure_link_expires$uri$remote_addr secret";
        
        if ($secure_link = "") {
            return 403;
        }
        
        if ($secure_link = "0") {
            return 410;
        }
        ...
    }

 

  • "/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647" 링크는 IP 주소가 127.0.0.1인 클라이언트의 "/s/link"에 대한 액세스를 제한
    링크의 수명은 2038년 1월 19일(GMT)까지 제한

 

  • UNIX에서 md5요청 인수 값은 다음과 같이 얻을 수 있음
    $ echo -n '2147483647/s/link127.0.0.1 secret' | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =

 

 

3. secure_link_secret 지시어

  • 요청된 링크의 진위 여부를 확인하는 데 사용되는 암호를 정의

  • 문맥: location
  • 사용 문법
    # 문법 : secure_link_secret 표현법
    secure_link_secret word;

 

  • 요청된 링크의 전체 URI은 아래와 같음
    1. hash → 링크와 secret 단어의 연결을 위해 계산된 MD5 해시의 16진수 표현
    2. prefix → 슬래시가 없는 임의의 문자열
    3. link → 요청 url
      # /접두사/해시/링크
      /prefix/hash/link

 

  • 요청된 링크가 진위 확인을 통과하면 $secure_link 변수가 요청 URI에서 추출된 링크로 설정
  • 그렇지 않으면 $secure_link 변수가 빈 문자열로 설정됨
    location /p/ {
        secure_link_secret secret;
     
        if ($secure_link = "") {
            return 403;
        }
     
        rewrite ^ /secure/$secure_link;
    }
     
    location /secure/ {
        internal;
    }

 

  • "/p/5e814704a28d9bc1914ff19fa0c4a00a/link" 요청은 내부적으로 "/secure/link"로 리디렉션
  • UNIX에서 예제의 해시 값은 아래와 같이 얻을 수 있음
    $ echo -n 'linksecret' | openssl md5 -hex

 

 

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

ngx_http_mp4_module 모듈  (0) 2023.09.24
ngx_http_referer_module 모듈  (0) 2023.09.23
ngx_http_realip_module 모듈  (0) 2023.09.23
ngx_http_slice_module 모듈  (0) 2023.09.22
ngx_http_split_clients_module 모듈  (0) 2023.09.22

+ Recent posts