SSL 인증서 발급하는 블로그를 써보았으니, 적용을 시켜볼 차례입니다.
Let's encrypt를 이용하여 SSL을 발급받은 경우 인증서가 발급되는 경로 입니다.
/etc/letsencrypt/live/<yourDomain>/fullchain.pem
/etc/letsencrypt/live/<yourDomain>/privkey.pem
nginx는
sites-enabled 경로의 심볼릭 링크를 읽어오는데
sites-available 경로에서 위의 심볼릭 링크 실제 환경설정 파일을 작성합니다.
설정하는 방법을 보면
/etc/nginx/nginx.conf
위 파일을 열어보시면 http 설정란안에 아래와 같이 설정되어 있는걸 볼 수 있습니다.
include /etc/nginx/sites-enabled/*;
nginx를 설치하면 환경설정 파일이 있는 경로 입니다.
/etc/nginx/sites-available/
/etc/nginx/sites-enabled/
위 경로에 들어갈 경우에 기본적으로 default 파일이 있습니다.
default에 있는 설정으로 실행되기 때문에 지워줍니다.
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
default파일을 지웠으니 새로 환경설정 파일을 만들어야겠죠?
파일이 존재하지 않는경우 생성하고, 편집모드로 들어가는 명령어 입니다.
sudo vi /etc/nginx/sites-available/myapp.conf
설정파일 이름은 myapp.conf로 지정 했습니다.
myapp.conf의 내부 설정을 보겠습니다.
server{
listen 80;
location / {
return 302 https://<yourDomain>/$1;
}
}
server{
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/<yourDomain>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<yourDomain>/privkey.pem;
location / {
root /<프로젝트경로>;
index index.html;
try files $uri $uri/ /index.html;
}
}
위의 설정을 설명 해드리겠습니다.
차례로 server1, server2 라고 보면
server1에서는
http로 접속했을시, https로 이동시키게 설정을 해놓았습니다.
server2에서는
ssl을 쓴다고 명시하고, ssl을 설정 하였고,
root 폴더를 설정해주었습니다. 이는 프로젝트의 default경로를 지정해줍니다.
index index.html은 client에서 접속한 경로에서 index.html을 기본적으로 반환하는 의미입니다.
try_files $uri $uri/ index.html; 은 차례로 파일이 있는지 검사하고 없으면 다음으로 넘어갑니다.
$uri는 http://domain/test.html 이렇게 접속하였을때 test.html파일이 있는지 확인합니다.
$uri/는 http://domain/test/ 를 요청했을때, 위에서 index index.html을 설정 했으니, test/index.html 파일을 반환합니다.
index.html은 인덱스 파일이 없는경우 반환하는데, 보통 404출력 html을 설정해놓습니다.
SSL인증서의 경우에는 인증서를 발급받았을때 보통 default경로로 설정하지만
가끔 커스텀경로로 설정하는 경우가 있으니 주의해야 합니다.
SSL은 자주 받는 기능인데 정리가 한번 필요한것 같아서 작성 하였습니다.
certbot 명령어도 적어놓겠습니다.
발급받은 인증서의 경로와 만료일자를 확인하는 명령어
certbot certificates
인증서 재발급 명령어
certbot renew
인증서 재발급 테스트 명령어 정상적으로 발급되는지 테스트 할 수 있습니다.
certbot renew --dry-run