SSL 이란?
Secure Socket Layer의 약자로 SSL 프로토콜은 웹서버와 브라우저 사이의 보안을 위해 만들어졌다.
대칭키를 이용하여 암호화 통신을 하는 원리이며, http 요청에 SSL 적용을 하여 https 통신을 한다.
이를 위해서 필요한 것이 SSL 인증서이고, 이를 발급받고 적용하는 과정을 간단하게 정리해 보았다.
SSL 인증서는 이 사이트가 신뢰성 있는 사이트라고 인증을 해주기 위한 것이다.
인증서에는 소유자의 e-mail 주소, 이름, 용도, 유효기간, 발행기관, public key 등이 포함되어 있다.
AWS EC2 인스턴스에 nginx 웹서버를 띄워 놓았다. 8080 포트로 접속 시 내가 만든 웹서버로 접속이 가능하다.
이 때 https 접속을 위한 ssl 인증서를 발급하기 위해서는 아래 과정을 따라하면 된다.
인증서 발급 중에는 보안그룹 및 Network ACL을 모두 허용된 상태에서 하는 것을 추천한다. 발급한 후에 보안정책을 적용하면 된다.
1. 필요한 패키지를 설치한다.
## Package 설치
# Redhat
sudo yum install -y certbot python3-certbot-nginx
# ubuntu
sudo apt install -y certbot python3-certbot-nginx
2. 인증서 발급
sudo certbot --nginx
보호하고자 하는 domain 주소를 입력하고, email 주소를 입력한 후 약관 동의를 하면 인증서 발급이 된다.
하지만 이렇게 간단할 리가 없다.
온갖 에러가 발생하는 것이 당연한 것.
1. 포트 충돌 에러
Encountered exception during recovery: certbot.errors.MisconfigurationError: nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
nginx restart failed:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
80 번 포트가 사용중이라면서 에러가 발생한다.
sudo lsof -i :80
위 명령어로 80 포트를 사용중인 프로세스의 PID를 확인한다.
그리고 kill -9 [PID] 프로세스를 종료한다.
그리고 위 과정을 다시 시도한다.
2. Nginx configuration 파일이 제대로 설정되어 있지 않았을 때
Could not automatically find a matching server block for {My domain address}.
Set the server_name directive to use the Nginx installer.
/etc/nginx/conf.d/default.conf 파일을 생성하고 아래 내용을 채워넣는다.(파일 이름은 상관없다.)
**한글로 된 부분을 채워넣으면 된다**
server {
if ($host = 도메인주소) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name 도메인주소;
# HTTP 요청을 HTTPS로 리디렉션
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name posco.d3square.rnddata.org;
# SSL 인증서 경로 설정
ssl_certificate /etc/letsencrypt/live/도메인주소/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/도메인주소/privkey.pem; # managed by Certbot
# SSL 보안 설정
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
proxy_pass http://localhost:포트번호;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
'네트워크' 카테고리의 다른 글
REST API란? (0) | 2023.09.04 |
---|