NGINX, React, Docker-compose, Certbot으로 HTTPS 적용하기

Jaeyeon Kim·2023년 8월 3일
1

Docker

목록 보기
3/3

http로 배포하는 것보다는 https로 배포하는 것이 보안성 측면에서도 좋고
사용자 입장에서도 좀 더 보안이 좋다는 느낌을 줄 수 있다!
Certbot으로 배포하고자 하는 웹사이트에 간단하게 https을 적용할 수 있다.

snap 설치하기

sudo apt update
sudo apt install snapd

certbot 설치하기

sudo snap install certbot --classic

인증서 발급하기

잘 정리된 글이 있으니, 이 글을 참고해주세요.

docker-compose.yml 수정

위에서 인증서가 발급된 경로를 잘 메모해둡니다.

version: "3.7"
services:
    nginx:
        container_name: frontend
        image: frontend_image
        ports:
            - "443:443"
        volumes:
            - /etc/letsencrypt/live/{도메인명}/fullchain.pem:/etc/ssl/cert.pem
            - /etc/letsencrypt/live/{도메인명}/privkey.pem:/etc/ssl/key.pem
        restart: always

host에서 인증서가 저장된 경로와 docker 컨테이너의 볼륨을 이어줍니다.

nginx.conf 수정

server {
    listen 443 ssl;
    listen [::]:443 ssl;

     # SSL 공개키, 개인키 경로 명시
    ssl_certificate /etc/ssl/cert.pem;
    ssl_certificate_key /etc/ssl/key.pem;

    # SSL 보안 설정
    ssl_session_cache shared:SSL:50m;
    ssl_session_timeout 1d;
    ssl_session_tickets off;

    # SSL 암호화 프로토콜 설정
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers off;
    ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

끝!

profile
낭만과 열정으로 뭉친 개발자 🔥

1개의 댓글

comment-user-thumbnail
2023년 8월 3일

정보 감사합니다.

답글 달기