본문 바로가기
코딩/cpp

[nginx] 설치 법 및 설정 법

by 적막한숲 2025. 9. 30.

Linux 24.04 LTS에서 Nginx 설치 절차

  • Install the prerequisites:

    sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
  • Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:

    curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
      | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
  • Verify that the downloaded file contains the proper key:

    gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
  • The The output should contain the full fingerprint "573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62" as follows:

    pub   rsa2048 2011-08-19 [SC] [expires: 2027-05-24]
        573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
    uid                      nginx signing key <signing-key@nginx.com>
  • Note that the output can contain other keys used to sign the packages.

  • 1. To set up the apt repository for stable nginx packages, run the following command:

    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
  • 2. If you would like to use mainline nginx packages, run the following command instead:

    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
  • 3. Set up repository pinning to prefer our packages over distribution-provided ones:

    echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
      | sudo tee /etc/apt/preferences.d/99nginx
  • To install nginx, run the following commands:

    sudo apt update
    sudo apt install nginx

For Begginger

prefix는 경로는 다음과 같다.

  • /usr/local/nginx/conf
  • /etc/nginx
  • /usr/local/etc/nginx
  • 여기서 나의 경우에는 /etc/nginx다*

Starting, Stopping, and Reloading Configuration

  • To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

    nginx -s signal
  • To stop nginx processes with waiting for the worker processes to finish serving current requests, the following command can be executed:

    nginx -s quit
  • To reload configuration, execute

    nginx -s reload

Serving Static Content

  • File Directory
    directory
      /data/www    > which my contain HTML files
          index.html이 보통 들어감. 
      /data/images > containing images

초기 Setting 방법

  • nginx 초기 setting 방법
  • prefix 경로를 찾는다. 여기서 나의 경우는 /etc/nginx/인데
  • 이 밑에 nginx.conf 파일을 찾아서 해결한다.
  • 이를 sudo nano로 열어서 편집을 한다.
http {
      server {
        listen 8080;
        location / {
             root /home/nginxServer/test1/data/www;
        }
        location ~ \.(gif|jpg|png)$ {
                root /home/nginxServer/test1/data/images;
        }
    }
}
  • http 괄호 안에 다음과 같은 형식으로 넣는다.
  • 이후에, systemctl 명령어를 써서 프로세스를 진행한다.
sudo systemctl start nginx
  • 파일 변경 후, reload 할 경우 다음 두가지 방식으로 갱신이 가능하다
    sudo nginx -s reload
    sudo systemctl reload nginx

'코딩 > cpp' 카테고리의 다른 글

[백준] 18870번  (0) 2025.10.01
[백준] 18111번  (0) 2025.10.01
[nginx] 초심자 가이드  (0) 2025.09.30
[nginx/포트폴리오 프로젝트] proxy_pass란 무엇인가  (0) 2025.09.30
[백준]11724번  (0) 2025.09.29