https로 접속하기

Yuusaku·2024년 1월 5일

http 를 이용해서 웹 서버를 배포하는 것을 실시하였다.

그러나 http 는 암호화가 되지 않은 전송방식이기 때문에 중간에서 데이터를 엿볼 수 있는 위험성이 있다. 이를 위해서 암호화 전송 방식인 https를 이용하여야 한다.

https 를 이용하기 위해서는 ssl 인증서를 발급받아야 한다.

ssl 인증서는 유료 발급기관과 무료 발급기관이 있는데, 무료 발급기관의 경우에는 갱신이 필요한 불편함이 따른다.

일단은 무료 발급기관인 Let's Encrypt의 서비스를 이용하도록 할 것이다.

EC2 서버에 접속한 후 certbot 을 설치하도록 한다.

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

Nginx 웹 서버에 사용할 certbot 인증서를 다운받는다.

sudo certbot certonly --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): xxx@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): my_domain.com

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for pybo.kr
Using default address 80 for authentication.
Waiting for verification...

ssl 인증서를 설치하였고 이 ssl 인증서를 nginx 에 적용해야 한다.

cd /etc/nginx/sites-available/
sudo nano project

nano를 이용해 내용을 다시 수정해준다.

server {
        listen 80;
        server_name pybo.kr;
        rewrite        ^ https://$server_name$request_uri? permanent;
}

server {
        listen 443 ssl;
        server_name pybo.kr;

        ssl_certificate /etc/letsencrypt/live/pybo.kr/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/pybo.kr/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        }
}
server {
        listen 443 ssl;
        server_name myproject.com;

        ssl_certificate /etc/ssl/certificate.crt; # managed by Certbot
        ssl_certificate_key /etc/ssl/private.key; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        }
}

이를 적용하기 위해 nginx 를 다시 시작한다.

sudo systemctl restart nginx.service

인스턴스의 인바운드 규칙을 편집하여 443 포트를 열어주어야 한다.

sudo python3 AI_Interview/web/main.py

0개의 댓글