본문 바로가기

리눅스

우분투에서 NGINX의 최신 버전을 설치하는 방법

728x90

우분투에서 NGINX의 최신 버전(안정 버전)을 설치하는 방법

nginx : High performance web server

 

Ubuntu : http://nginx.org/en/linux_packages.html#Ubuntu

테스트 환경

  • 운영체제 버전 정보
$ lsb_release -d
Description:    Ubuntu 22.04.2 LTS

NGINX 설치

필수 구성 요소 설치

sudo apt-get update
sudo apt-get install -y curl gnupg2 ca-certificates lsb-release

ubuntu-keyring, apt-transport-https 패키지 설치

sudo apt-get install -y ubuntu-keyring apt-transport-https

nginx.list 파일 생성

NGINX 공식 저장소에서 서명 키 가져오기

curl -s 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
$ 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: 2024-06-14]
      573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid                      nginx signing key <[email protected]>

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
$ 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
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu jammy nginx

APT 저장소 업데이트

sudo apt-get update
728x90

NGINX 패키지 설치

sudo apt-get install -y nginx
$ sudo apt-get install -y nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  nginx
...
Preparing to unpack .../nginx_1.24.0-1~jammy_amd64.deb ...
----------------------------------------------------------------------

Thanks for using nginx!

Please find the official documentation for nginx here:
* https://nginx.org/en/docs/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html

Commercial subscriptions for nginx are available on:
* https://nginx.com/products/

----------------------------------------------------------------------
Unpacking nginx (1.24.0-1~jammy) ...
Setting up nginx (1.24.0-1~jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...

Running kernel seems to be up-to-date.

The processor microcode seems to be up-to-date.

설치된 NGINX 버전 정보 확인

nginx -v
$ nginx -v
nginx version: nginx/1.22.1

NGINX 서비스 시작 및 활성화

sudo systemctl --now enable nginx

NGINX 서비스 상태 확인

sudo systemctl status nginx

NGINX 버전 정보 숨기기

nginx.conf 편집

vim /etc/nginx/nginx.conf
http {
...
    server_tokens off;
...
    server {
        listen 80;
        server_name _;
        ...
        location /nginx_status {
            # Nginx status 페이지 설정
            stub_status;
            access_log off;
            allow 127.0.0.1;
            allow 192.168.56.0/24;
            deny all;
        }
    }
}

NGINX 구문 검사

nginx -t
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

NGINX 서비스 재시작

sudo systemctl restart nginx

 

참고URL

- http://nginx.org/en/linux_packages.html#Debian

- Nginx 설치 및 구성 : Install and configure Nginx | Ubuntu

 

728x90