본문 바로가기
Programming

[Django] HTTPS 인증

by 느리게 걷는 즐거움 2022. 12. 6.
728x90
반응형

1. Lets Encrypt 인증서 설치

인증서를 설치하고 인증서를 생성한다.

# certbot 설치
sudo apt-get install certbot
sudo apt-get install python3-certbot-nginx


# 인증서 발급
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): [자신의 email정보]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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): [자신의 도메인 이름]
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for pybo.kr
Using default address 80 for authentication.
Waiting for verification...

2. 인증서 설정을 위한 nginx 설정

/etc/nginx-enabled/

server {
	listen 80;
	server_name [웹사이트이름.com www.웹사이트이름.com];

	location / {
		proxy_pass http://127.0.0.1:8000/;

		proxy_buffer_size          128k;
		proxy_buffers              4 256k;
		proxy_busy_buffers_size    256k;
	}
	location /static/ {
		alias [실제 장고 static 폴더 path];
	}
}

server {
	listen 443 ssl;
	server_name [웹사이트이름.com];

	ssl_certificate /etc/letsencrypt/live/[웹사이트이름.com]/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/[웹사이트이름.com]/privkey.pem;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE*****!RC4";
	ssl_prefer_server_ciphers on;

        location = /favicon.ico { access_log off; log_not_found off; }

        location /static {
                alias [실제 장고 static 폴더 path];
        }
	location / {
		proxy_pass http://127.0.0.1:8000/;

		proxy_buffer_size          128k;
		proxy_buffers              4 256k;
		proxy_busy_buffers_size    256k;
	}

}

3. HTTPS port 방화벽 해제

 SSL의 포트인 443번 포트의 방화벽 해제가 필요하다

4. Nginx 설정 적용을 위한 Nginx 재시작

systemctl restart nginx.service

 

상세한 설명은 아래 pybo site를 참고 부탁드립니다.
아래 pybo게시판을 참고하였습니다.

Reference : https://wikidocs.net/164372

728x90
반응형