[Setting | Ubuntu] Nginx 설치 및 인증서 설정

우분투 환경에 Nginx를 설치하고 서비스에 인증서 세팅하는 방법을 정리한다.


작성일 : 2023-12-20
OS : Ubuntu 22.04 LTS
Nginx : 1.18.0

1> apt update & upgrade

sudo apt update
sudo apt upgrade

2> 이전버전 삭제

sudo apt remove nginx

3> nginx 설치

sudo apt install nginx

4> letsencrypt 설치

sudo apt install certbot
sudo apt install python3-certbot-nginx

5> proxy 설정

server {
    listen       80;
    server_name  {도메인};

    location / {
        proxy_pass http://{target IP};
        proxy_set_header Host {도메인};
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

6> 인증서 설치

# 최초설치
certbot
# 갱신
certbot renew

7> 인증서 자동갱신 설정

crontab -e
----------------------------------------
0 12 * * * /usr/bin/certbot renew --quiet