1. Certbot 설치
우선 Certbot을 설치해야 합니다. 이는 Let’s Encrypt 인증서를 발급받기 위한 도구입니다.
Debian/Ubuntu:
sudo apt update
sudo apt install certbot python3-certbot-nginx
CentOS/RHEL:
sudo yum install epel-release
sudo yum install certbot python3-certbot-nginx
2. 인증서 발급
Certbot을 사용하여 인증서를 발급받고, NGINX 설정에 자동으로 적용할 수 있습니다.
sudo certbot --nginx -d xxx.moyo.pw
위 명령어는 xxx.moyo.pw
도메인에 대한 인증서를 발급받고 NGINX 설정을 자동으로 업데이트합니다. Certbot은 NGINX 서버 블록을 수정하여 SSL 설정을 추가합니다.
3. NGINX 설정 확인
Certbot이 NGINX 설정을 자동으로 업데이트한 후, 설정 파일을 확인하고 필요시 수정할 수 있습니다. 예시 설정은 다음과 같습니다:
server {
listen 80;
server_name xxx.moyo.pw;
location / {
proxy_pass http://localhost:8080;
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;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxx.moyo.pw/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxx.moyo.pw/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://localhost:8080;
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;
}
}
4. NGINX 설정 테스트 및 재시작
설정 파일에 오류가 없는지 확인하고, NGINX를 재시작합니다.
sudo nginx -t
sudo systemctl restart nginx
5. 인증서 자동 갱신
Let’s Encrypt 인증서는 90일 동안 유효합니다. Certbot은 자동 갱신을 지원하며, 일반적으로 /etc/cron.d
또는 systemd timer
에 자동 갱신 스크립트가 추가됩니다. 갱신 테스트를 수동으로 실행해볼 수 있습니다:
sudo certbot renew --dry-run
이 명령어가 성공적으로 실행되면, 인증서 갱신이 자동으로 이루어집니다.
이제 xxx.moyo.pw
도메인에 대한 HTTPS 요청이 NGINX를 통해 8080 포트로 프록시될 것입니다.
#LETS_ENCRYPT #도메인_인증서 #인증서 #NGINX
