티스토리 뷰
https
서버에서 웹을 배포하면 약속된 특정 프로토콜을 통하여 client에게 웹페이지 소스를 보내주게 된다.
이 때 주로 사용되는 프로토콜이 http (HyperText Transfer Protocol) , https (HyperText Transfer Protocol Secure)이다.
https는 http의 보안상의 취약점(세션 데이터 암호화)을 개선된 프로토콜이다.
보통의 프로젝트를 배포할때 별도의 인증서와 도메인이 없다면 http로 배포되는데 이를 https로 바꿔보자
적용하기
환경
- ubuntu
- apache
일반적으로 웹을 배포하는 환경인 linux + apache을 기준으로 작성했다.
1. 도메인 구하기
https을 적용하기 위해선 도메인에 대한 인증이 필요하기 때문에 도메인 서비스에서 자신의 도메인을 구해오자
ex) www.example.com
2. SSL 인증서 발급받기
인증서를 발급 받는 방법에는 여러가지가 있지만 무료 오픈소스인 letsencrypt를 써보자
apache, ngnix와 연동이 가능하고(웹서버에서 인증서를 자동으로 가져다 configure을 변경해줌) 또 standalone으로도 발급받을 수 있다.
다만 3개월마다 갱신을 해주어야 한다. (crontab 으로 자동화 가능)
letsencrypt 설치
sudo apt update
sudo apt-get install letsencrypt -y
인증서 발급
# Obtain and install a certificate:
certbot
# Obtain a certificate but don't install it:
certbot certonly
# You may specify multiple domains with -d and obtain and
# install different certificates by running Certbot multiple times:
certbot certonly -d example.com -d www.example.com
certbot certonly -d app.example.com -d api.example.com
인증서를 발급받을 때 80 포트를 열어야 한다.
발급받은 인증서는 /etc/letsencrypt/live/ 에 저장된다
인증서를 발급받을 때 아래의 plugins들을 사용할 수 있다.
- apache
- nginx
- webroot
- standalone
- DNS plugins
- manual
인증서 확인
certbot certificates
인증서 삭제
certbot delete
인증서 갱신
certbot renew
3. 인증서를 웹서버(apache)에 연동하기
기존의 배포하던 apache conf를 수정하자
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot "var/www/html/"
</VirtualHost>
기존의 http로 배포하던 conf 를
<VirtualHost *:80>
ServerName www.example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com%{REQUEST_URI}
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot "/var/www/html/"
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
</VirtualHost>
이렇게 바꾸어주자.
RewriteEngine은 80 포트로 접근하는 request들을 443 포트 즉 https로 돌려준다.
'Web' 카테고리의 다른 글
SSR, CSR 차이 (Django vs React) (0) | 2021.12.26 |
---|
- Total
- Today
- Yesterday
- 뿌요뿌요
- 정보보호병
- 서버 관리
- 프로젝트
- pintos
- 런타임 에러
- 웹IDE
- letsencrypt
- 코딩
- 해커톤
- react
- 시간 초과
- 토이프로젝트
- ttyd
- Django
- 백준
- Web
- 사이버정보지식방
- 분할 정복
- 리눅스
- 뿌요뿌요 테트리스
- System call
- 싸지방
- 구름ide
- C
- 앱
- FastAPI
- pvm
- Python
- codeanywhere
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |