← 전체로 돌아가기
스킬 linux

NGINX Let's Encrypt HTTPS 설정

NGINX에 Let's Encrypt로 HTTPS를 쉽게 설정하는 법

nginxlets-encrypthttpssslcertbot

NGINX에 Let's Encrypt로 HTTPS 설정하는 실용 가이드.

  • NGINX & 방화벽 설정: bash sudo apt update && sudo apt install nginx -y sudo systemctl start nginx && sudo systemctl enable nginx sudo ufw allow 'Nginx Full' && sudo ufw enable
  • 도메인 연결: DNS A 레코드를 서버 IP로 설정해줘.
  • Certbot 설치 & 인증서 발급: bash sudo apt install certbot python3-certbot-nginx -y sudo certbot --nginx -d your_domain # 도메인 변경 필요
  • HTTPS 적용 & 확인: bash sudo nginx -t && sudo systemctl reload nginx https://your_domain으로 접속 확인.
  • 자동 갱신: sudo certbot renew --dry-run으로 테스트. (Certbot이 자동 처리)

여기서 배울 것

  1. NGINX 설치 및 기본 방화벽 설정 방법을 익힌다.
  2. Let's Encrypt Certbot으로 SSL 인증서를 발급받는 과정을 이해한다.
  3. NGINX에 HTTPS를 적용하고 테스트하는 방법을 배운다.
  4. SSL 인증서 자동 갱신 설정을 확인한다.
원본 파일 보기 (.claude/skills/tn-https-lets-encrypt-nginx/SKILL.md)
---
name: NGINX Let's Encrypt HTTPS 설정
description: This skill should be used when the user asks to set up HTTPS for a website using NGINX and Let's Encrypt, including installing NGINX, configuring DNS, obtaining SSL certificates, and setting up automatic renewal.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/HTTPS (let’s encrypt, nginx) 2ddd7efd824b80379feadb5a9897d580.md
---

# HTTPS (let’s encrypt, nginx)

**HTTPS**

let's encrypt, nginx

### 1. **NGINX 설치 및 기본 설정**

1. **NGINX 설치**:
    
    ```bash
    sudo apt update
    sudo apt install nginx -y
    ```
    
2. **NGINX 실행 확인**:
    
    ```bash
    sudo systemctl start nginx
    sudo systemctl enable nginx
    sudo systemctl status nginx
    ```
    
    브라우저에서 서버의 IP 주소를 입력하면 NGINX 기본 페이지가 보여야 합니다.
    
3. **방화벽 설정**:
    
    ```bash
    sudo ufw allow 'Nginx Full'
    sudo ufw enable
    
    ```
    

---

### 2. **도메인 이름 연결**

- 도메인 이름을 서버의 퍼블릭 IP 주소에 연결합니다.
- 도메인의 DNS 설정에서 `A 레코드`를 서버 IP로 설정하세요.
    
    ![Screenshot 2024-12-23 at 9.40.20 PM.png](HTTPS%20(let%E2%80%99s%20encrypt,%20nginx)/Screenshot_2024-12-23_at_9.40.20_PM.png)
    

---

### . **Let's Encrypt 설치**

1. **Certbot 설치**:
    
    ```bash
    sudo apt install certbot python3-certbot-nginx -y
    ```
    
2. **HTTPS 인증서 생성**:
아래 명령으로 도메인에 대한 인증서를 발급합니다:
    
    ```bash
    sudo certbot --nginx -d your_domain
    
    in my case
    sudo certbot --nginx -d ec2seoul.flaresolution.com
    ```
    
    `your_domain`을 실제 도메인으로 변경하세요.
    
3. **이메일 입력 및 약관 동의**:
    - 이메일 주소를 입력하고 Let's Encrypt 약관에 동의하세요.
    - 도메인의 DNS 설정이 올바르다면 인증이 진행되고 인증서가 발급됩니다.

---

### 4. **NGINX HTTPS 설정**

- Certbot이 NGINX 설정 파일을 자동으로 업데이트하여 HTTPS를 활성화합니다.
- 설정 파일은 `/etc/nginx/sites-available/your_domain`에 저장됩니다.
- 변경 사항이 적용되었는지 확인:
    
    ```bash
    sudo nginx -t
    sudo systemctl reload nginx
    ```
    

---

### 5. **HTTPS 연결 테스트**

- 브라우저에서 `https://your_domain`으로 접속하여 HTTPS가 활성화되었는지 확인하세요.

---

### 6. **SSL 인증서 자동 갱신 설정**

Let's Encrypt 인증서는 90일간 유효합니다. 자동 갱신 설정을 추가하세요:

1. **갱신 테스트**:
    
    ```bash
    sudo certbot renew --dry-run
    ```
    
    성공하면 자동 갱신이 작동하고 있습니다.
    
2. **크론잡 설정**:
Certbot 설치 시 기본적으로 크론 작업이 생성되므로 별도의 설정은 필요하지 않습니다.

---