시스템 환경 확인
본 가이드는 Ubuntu 24.04.2 LTS (Noble Numbat) 환경을 기준으로 작성되었습니다. 설치를 시작하기 전 시스템 버전을 확인합니다.
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
...
필수 의존성 패키지 설치
OpenResty를 소스 코드에서 빌드하기 위해서는 컴파일러와 관련 라이브러리가 필요합니다. 터미널에서 다음 명령어를 실행하여 필요한 패키지들을 설치합니다.
sudo apt-get update
sudo apt-get install -y build-essential libpcre3-dev \
libssl-dev perl make curl zlib1g-dev libreadline-dev
OpenResty 소스 빌드 및 설치
최신 안정 버전의 OpenResty 소스를 다운로드하고 컴파일을 진행합니다. 여기서는 PCRE JIT 및 IPv6 지원 옵션을 포함합니다.
# 소스 다운로드 및 압축 해제
wget https://openresty.org/download/openresty-1.27.1.1.tar.gz
tar -xzvf openresty-1.27.1.1.tar.gz
cd openresty-1.27.1.1
# 빌드 설정 및 설치
./configure --with-pcre-jit --with-ipv6
make -j$(nproc)
sudo make install
애플리케이션 환경 설정
OpenResty를 실행하기 위한 전용 작업 디렉토리와 설정 파일을 생성합니다.
mkdir -p ~/resty-app/logs ~/resty-app/conf
cd ~/resty-app
conf/nginx.conf 파일을 생성하고 아래와 같이 기본적인 Lua 블록을 포함한 설정을 작성합니다.
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<h1>OpenResty is running!</h1>")
ngx.say("<p>Powered by LuaJIT.</p>")
}
}
}
}
서비스 구동 및 관리
OpenResty 바이너리 경로를 환경 변수에 추가하거나 절대 경로를 사용하여 서비스를 제어합니다.
# 경로 설정 (필요 시)
export PATH=/usr/local/openresty/bin:$PATH
# 서비스 시작 (-p는 프로젝트 루트, -c는 설정 파일 경로)
openresty -p `pwd`/ -c conf/nginx.conf
# 서비스 관리 명령
openresty -p `pwd`/ -s reload # 설정 재로드
openresty -p `pwd`/ -s stop # 즉시 정지
openresty -p `pwd`/ -s quit # 정상 종료
Systemd 서비스 등록 (자동 실행 설정)
서버 부팅 시 OpenResty가 자동으로 실행되도록 systemd 유닛 파일을 생성합니다.
sudo nano /etc/systemd/system/openresty.service
파일 내부에 다음 내용을 입력합니다. 경로는 기본 설치 경로인 /usr/local/openresty를 기준으로 합니다.
[Unit]
Description=OpenResty HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
서비스를 활성화하고 상태를 확인합니다.
sudo systemctl daemon-reload
sudo systemctl enable openresty
sudo systemctl start openresty
sudo systemctl status openresty
동작 확인
curl 명령어를 통해 서버가 정상적으로 응답하는지 테스트합니다.
curl http://localhost:8080/
정상적으로 설치되었다면 작성한 Lua 블록의 HTML 결과가 출력됩니다.
설정 구조 최적화
관리 효율을 높이기 위해 설정 파일을 모듈화할 수 있습니다. 메인 nginx.conf 하단에 include 구문을 추가하여 별도의 설정 디렉토리를 로드하도록 구성합니다.
# nginx.conf 내 http 블록 추가 예시
http {
...
include /usr/local/openresty/nginx/conf.d/*.conf;
include /usr/local/openresty/nginx/sites-enabled/*;
}
이후 필요한 디렉토리를 생성하여 관리합니다.
sudo mkdir -p /usr/local/openresty/nginx/conf.d/
sudo mkdir -p /usr/local/openresty/nginx/sites-enabled/