MSA 트레이닝 센터
NGINX Unit Language 모듈 소개
NGINX Unit Language 모듈 소개
이 가이드에서는 NGINX Unit Language와 관련된 주요 개념, 설치 및 설정 방법, 언어 모듈 활용법 등을 다룹니다.
NGINX Unit Language 모듈 - External
External 모듈은 일반적인 언어 라이브러리나 패키지로, 다른 패키지처럼 설치됩니다. 이들은 애플리케이션 실행 공간에서 Unit과 통신하며 일반적인 웹 기능을 제공합니다.
- Go: Unit 지원은 애플리케이션에 가져와 Unit을 인식하게 만드는 패키지를 통해 구현됩니다.
- Node.js: Unit은 npm에 호스팅된 패키지를 통해 지원됩니다. 이 패키지는 애플리케이션 코드에서
require를 통해 호출하며, npm 저장소에서 설치하거나 Node.js 버전에 맞게 Unit 소스에서 빌드할 수 있습니다. - WebAssembly: Unit은 Wasmtime 런타임에 바이트코드 실행을 위임합니다. 이 런타임은 언어 모듈 설치 시 또는 소스 빌드 과정에서 설치됩니다.
NGINX Unit Language 모듈 - Embedded
내장 모듈은 Unit이 시작 시 로드하는 공유 라이브러리입니다. 시스템에서 모듈을 확인하려면 Unit에 쿼리하세요.
unitd -h
출력 예시:
...
--log FILE 로그 파일 이름 설정
기본값: "/default/path/to/unit.log"
--modules DIRECTORY 모듈 디렉토리 이름 설정
기본값: "/default/modules/path/"
현재 실행 중인 Unit 확인:
ps ax | grep unitd
...
unit: main v1.33.0 [unitd --log /runtime/path/to/unit.log --modules /runtime/modules/path/ ... ]
모듈 디렉토리 확인:
ls /path/to/modules
java.unit.so php.unit.so ruby.unit.so wasm_wasi_component.unit.so
perl.unit.so python.unit.so wasm.unit.so
NGINX Unit Lanaguage 모듈 버전 확인
Unit 로그 파일에서 시작 시 로드된 모듈을 확인할 수 있습니다
less /path/to/unit.log
...
discovery started
module: <언어> <버전> "/path/to/modules/<모듈 이름>.unit.so"
...
언어 버전이 나열되지 않은 경우 해당 언어 버전에 의존하는 앱은 실행할 수 없습니다. 새 모듈을 추가하려면 다음 단계를 따르세요
- 공식 언어 패키지 사용: 통합 및 유지관리를 쉽게 하기 위해 가능하면 공식 패키지를 사용하세요.
- 타사 저장소 확인: Unit을 타사 저장소에서 설치한 경우, 적합한 언어 패키지가 있는지 확인하세요.
- 사용자 정의 패키지 생성: 재사용 가능한 맞춤형 솔루션이 필요하다면, Unit 옆에 설치할 수 있는 자체 패키지를 준비하세요.
사용자 정의 모듈 패키징
공식 Unit 패키지에서 아직 제공되지 않는 언어 버전을 실행해야 할 경우에도 패키지 설치의 편리함을 유지하고자 한다면, 사용자 정의 패키지를 직접 빌드하여 공식 배포판 옆에 설치할 수 있습니다. 이 경우, 공식 배포판을 선행 조건으로 설정하여 함께 사용할 수 있도록 구성해야 합니다.
다음은 공식 Unit 패키지 옆에 설치할 사용자 정의 PHP 7.3 모듈을 패키징하는 예제입니다. 필요에 따라 명령어를 조정하여 자신의 상황에 맞게 사용하세요.
.deb 패키지 생성
현재 시스템용으로 패키징 중이며 공식 Unit 패키지가 설치되어 있다고 가정하면, 아래 명령어를 실행하여 Unit 모듈 패키지를 빌드 및 설치할 수 있습니다.
1. 패키지의 사전 요구 사항을 설치해야 합니다. 여기서는 Debian 10에서 PHP 7.3을 설정하는 과정을 예로 들고 있습니다.
apt update
apt install ca-certificates apt-transport-https debian-archive-keyring
curl --output /usr/share/keyrings/php-keyring.gpg \
https://packages.sury.org/php/apt.gpg
echo "deb [signed-by=/usr/share/keyrings/php-keyring.gpg] \
https://packages.sury.org/php/ buster main" > /etc/apt/sources.list.d/php.list
apt update
apt install php7.3
apt install php-dev libphp-embed
2. 패키지를 위한 스테이징 디렉토리를 생성하세요.
export UNITTMP=$(mktemp -d -p /tmp -t unit.XXXXXX)
mkdir -p $UNITTMP/unit-php7.3/DEBIAN
cd $UNITTMP
3. unitd –version을 실행하고 ./configure 플래그를 기록하되, --ld-opt와 --njs는 제외하세요.
curl -O https://sources.nginx.org/unit/unit-1.33.0.tar.gz
tar xzf unit-1.33.0.tar.gz
cd unit-1.33.0
./configure FLAGS W/O --LD-OPT & --NJS
./configure php --module=php7.3 --config=php-config
make php7.3
mkdir -p $UNITTMP/unit-php7.3/MODULESPATH
mv build/php7.3.unit.so $UNITTMP/unit-php7.3/MODULESPATH
이것은 dpkg-deb에 적합한 폴더 구조를 생성하며, DEBIAN 폴더는 패키지 정의를 저장할 것입니다.
4. Unit의 소스를 다운로드하고, 사용자 정의 모듈을 구성 및 빌드한 후 Unit이 이를 찾을 수 있는 위치에 배치하세요.
curl -O https://sources.nginx.org/unit/unit-1.33.0.tar.gz
tar xzf unit-1.33.0.tar.gz # Unit의 소스를 unit-1.33.0 하위 디렉토리에 압축 해제
cd unit-1.33.0
./configure FLAGS W/O --LD-OPT & --NJS # 이전 단계에서 기록한 ./configure 플래그 사용
./configure php --module=php7.3 --config=php-config # 모듈 자체를 구성
make php7.3 # build/ 하위 디렉토리에 모듈 빌드
mkdir -p $UNITTMP/unit-php7.3/MODULESPATH # ./configure 또는 기본값으로 설정된 모듈 경로 사용
mv build/php7.3.unit.so $UNITTMP/unit-php7.3/MODULESPATH # 패키지에 모듈 추가
5. $UNITTMP/unit-php7.3/DEBIAN/control 파일을 다음과 같이 생성하세요
Package: unit-php7.3
Version: 1.33.0
Comment0: Use Unit's package version for consistency: 'apt show unit | grep Version'
Architecture: amd64
Comment1: To get current architecture, run 'dpkg --print-architecture'
Comment2: For a list of other options, run 'dpkg-architecture -L'
Depends: unit (= 1.33.0-1~buster), php7.3, libphp-embed
Comment3: Specify Unit's package version to avoid issues when Unit updates
Comment4: Again, run 'apt show unit | grep Version' to get this value
Maintainer: Jane Doe
Description: Custom PHP 7.3 language module for NGINX Unit 1.33.0
파일을 저장하고 닫으세요.
6. 패키지를 빌드하고 설치하려면 다음 명령어를 실행하세요
dpkg-deb -b $UNITTMP/unit-php7.3
dpkg -i $UNITTMP/unit-php7.3.deb
.rpm 패키지 생성
현재 시스템용으로 패키징 중이며 공식 Unit 패키지가 설치되어 있다고 가정하면, 아래 명령어를 실행하여 Unit 모듈 패키지를 빌드 및 설치할 수 있습니다.
1. 패키지의 사전 요구 사항을 설치해야 합니다. 여기서는 Fedora 30에서 PHP 7.3을 설정하는 과정을 예로 들고 있습니다.
yum install -y php-7.3.8
yum install php-devel php-embedded
2. RPM 개발 도구를 설치하고 디렉토리 구조를 준비하세요.
yum install -y rpmdevtools
rpmdev-setuptree
3. 사용자 정의 패키지의 빌드 명령을 저장할 .spec 파일을 작성하세요.
cd ~/rpmbuild/SPECS
rpmdev-newspec unit-php7.3
4. unitd –version을 실행하고 ./configure 플래그를 기록하되, --ld-opt와 --njs는 제외하세요.
unitd --version
unit version: 1.33.0
configured as ./configure FLAGS
5. unit-php7.3.spec 파일을 편집하여 Unit의 소스를 다운로드하고 사용자 정의 모듈을 구성 및 빌드한 다음, Unit이 해당 모듈을 찾을 수 있는 위치에 배치하는 명령을 추가하세요.
Name: unit-php7.3
Version: 1.33.0
# Use Unit's package version for consistency: 'yum info unit | grep Version'
Release: 1%{?dist}
Summary: Custom language module for NGINX Unit
License: ASL 2.0
# Unit uses ASL 2.0; your license depends on the language you are packaging
URL: https://example.com
BuildRequires: gcc
BuildRequires: make
BuildRequires: php-devel
BuildRequires: php-embedded
Requires: unit = 1.33.0
# Specify Unit's package version to avoid issues when Unit updates
# Again, run 'yum info unit | grep Version' to get this value
Requires: php >= 7.3
Requires: php-embedded
%description
Custom language module for NGINX Unit 1.33.0 (https://unit.nginx.org).
Maintainer: Jane Doe
%prep
curl -O https://sources.nginx.org/unit/unit-1.33.0.tar.gz
# Downloads Unit's sources
tar --strip-components=1 -xzf unit-1.33.0.tar.gz
# Extracts them locally for compilation steps in the %build section
%build
./configure FLAGS W/O --LD-OPT & --NJS
# Configures the build; use the ./configure flags noted in the previous step
./configure php --module=php7.3 --config=php-config
# Configures the module itself
make php7.3
# Builds the module
%install
DESTDIR=%{buildroot} make php7.3-install
# Adds the module to the package
%files
%attr(0755, root, root) "MODULESPATH/php7.3.unit.so"
# Lists the module as package contents to include it in the package build
# Use the module path set by ./configure or by default
파일을 저장하고 닫으세요.
6. 패키지를 빌드하고 설치하려면 다음 명령어를 실행하세요.
rpmbuild -bb unit-php7.3.spec
...
Wrote: /home/user/rpmbuild/RPMS//unit-php7.3-..rpm
...
yum install -y /home/user/rpmbuild/RPMS//unit-php7.3-..rpm
NGINX Unit Language는 애플리케이션 서버와 코드 간의 원활한 연결을 가능하게 하는 중요한 다리입니다. 이 가이드는 NGINX Unit을 활용하여 웹 애플리케이션을 배포하고 관리하는 첫걸음을 제공합니다. NGINX Unit은 범용 웹 애플리케이션 서버로, 엔터프라이즈급 복잡한 배포 환경부터 간단한 개인 프로젝트까지 모두 지원할 수 있는 강력한 빌딩 블록입니다.
더욱 다양한 NGINX Unit의 모듈 설정 방법을 알아보기 위해 MSA 트레이닝 센터를 확인해거나 NGINX STORE에 직접 문의하여 사용 사례에 맞는 모듈을 상담 받아보세요.