여러분이 우분투를 막 설치를 끝내고 Nginx를 설치하게 되면, 아마도 오래된 저장소의 Nginx의 버전이 설치될 겁니다. 이 가이드는 새로 설치하던, 이미 설치가 된 구버전이나 운영 중인 서비스가 있어도, Nginx의 최신버전을 설치할 수 있는 초보자를 위한 가이드입니다.
우분투 20.04 “focal”, 우분투 22.04 “jammy”, 우분투 24.04 “noble” 모두 아래 설명한 방법으로 설치 또는 업그레이드가 가능합니다. 이 가이드는 Nginx의 공식문서를 따릅니다.
글이 작성된 시점으로 현재 최신 버전은 아래와 같습니다.
Changes with nginx 1.26.3 05 Feb 2025
기존 레거시 저장소 정리
먼저 기존 nginx.org
패키지를 삭제하고 최신버전으로 업데이트해야 합니다.
기존 저장소 제거
sudo rm -f /etc/apt/sources.list.d/nginx.list
sudo apt update
기존 저장소를 제거했으므로, 이제 최신 Nginx 공식 저장소를 추가합니다.
필수 패키지 설치
먼저 apt
가 패키지 서명을 검증할 수 있도록 필요한 도구를 설치합니다.
sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
Nginx 공식 서명 키 가져오기
Nginx 패키지를 안전하게 설치할 수 있도록 서명 키를 가져옵니다.
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
키가 정상적으로 저장되었는지 확인 >
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
출력 결과가 아래와 같아야 합니다.
...
pub rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>
Nginx 최신 Stable 저장소 추가
공식 Nginx 스테이블 버전을 사용할 것이므로 다음 명령어를 실행합니다.
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
만약 **Mainline (개발 버전)**을 원하면 아래 명령어를 대신 사용합니다. (이번 경우는 Stable 버전이므로 실행할 필요 없음)
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
공식 Nginx 패키지를 우선하도록 설정
우분투 기본 레포지토리보다 nginx.org
저장소가 우선 적용되도록 설정합니다.
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx
이제 패키지 정보를 새로고침합니다.
sudo apt update
설치 가능한 Nginx 버전 확인
Nginx 최신 버전이 설치 가능한지 확인합니다.
apt list -a nginx
출력 예시:
root@663bbb4a90826:/etc/nginx# apt list -a nginx
Listing... Done
nginx/stable 1.26.3-1~jammy amd64 [upgradable from: 1.18.0-6ubuntu14.5]
nginx/stable 1.26.2-1~jammy amd64
nginx/stable 1.26.1-2~jammy amd64
nginx/stable 1.26.1-1~jammy amd64
nginx/stable 1.26.0-1~jammy amd64
nginx/stable 1.24.0-1~jammy amd64
nginx/stable 1.22.1-1~jammy amd64
nginx/stable 1.22.0-1~jammy amd64
nginx/stable 1.20.2-1~jammy amd64
nginx/jammy-updates,jammy-updates,jammy-security,jammy-security,now 1.18.0-6ubuntu14.5 amd64 [installed,upgradable to: 1.26.3-1~jammy]
nginx/jammy,jammy 1.18.0-6ubuntu14 amd64
여기서 1.26.
* 이 목록에 있으면 설치할 수 있습니다.
기존 설정 유지
운영 중인 사이트가 있다면, 설정 파일을 유지하면서 업그레이드해야 합니다. 없다면 바로 설치단계를 진행하세요.
설정 백업
sudo cp -r /etc/nginx /etc/nginx.bak
설정 파일 비교
diff -r /etc/nginx /etc/nginx.bak
차이가 있는 파일이 있다면 수동으로 확인하여 수정합니다.
Nginx 1.26.3 설치 및 업그레이드
이제 최신 버전을 설치합니다.
sudo apt install -y nginx
운영 중인 사이트의 기본 환경을 유지하려면, 기존의 설정 파일을 유지해야 합니다.
따라서 **”N” 또는 “O” (keep your currently-installed version)**을 선택하면 됩니다.
Configuration file '/etc/nginx/nginx.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ? N
📌 옵션 설명
- Y or I → 패키지 관리자가 제공하는 새로운 nginx.conf를 설치 (현재 설정이 덮어쓰기됨 ❌)
- N or O → 현재 설치된 설정 파일을 유지 (운영 중인 사이트 설정 유지됨 ✅)
- D → 새로운 버전과 현재 버전의 차이점(diff)을 표시
- Z → 셸을 열어 직접 파일을 확인 후 결정
설치 후 Nginx 버전 확인:
nginx -v
출력 예시:
nginx version: nginx/1.26.3
Nginx 서비스 재시작
설정 파일 테스트
sudo nginx -t
출력 예시:
root@663bbb4a90826:/etc/nginx# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl restart nginx
서비스 상태 확인:
sudo systemctl status nginx
출력 예시:
root@663bbb4a90826:/etc/nginx# sudo systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Fri 2025-02-07 22:51:42 UTC; 10h ago
Docs: https://nginx.org/en/docs/
Process: 2518926 ExecStart=/usr/sbin/nginx -c ${CONFFILE} (code=exited, status=0/SUCCESS)
Main PID: 2518927 (nginx)
Tasks: 2 (limit: 1062)
Memory: 2.1M (peak: 2.5M)
CPU: 78ms
CGroup: /system.slice/nginx.service
├─2518927 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
└─2518928 "nginx: worker process"
Feb 07 22:51:42 663bbb4a90826 systemd[1]: Starting nginx.service - nginx - high performance web server...
Feb 07 22:51:42 663bbb4a90826 systemd[1]: Started nginx.service - nginx - high performance web server.
자동 시작 확인
서버 재부팅 후에도 Nginx가 자동으로 시작되도록 설정되어 있는지 확인합니다.
sudo systemctl is-enabled nginx
출력이 **enabled
**라면 정상입니다.
만약 disabled
라면 자동 시작을 활성화합니다.
sudo systemctl enable nginx