카테고리 없음
Nginx 무료SSL 적용
홍이순이
2023. 10. 19. 02:15
Let's Encrypt는 무료 SSL/TLS 인증서를 제공하는 인증 기관입니다.
CentOS 서버에서 Let's Encrypt SSL 인증서를 등록하고 Nginx 웹 서버에 적용하는 절차는 다음과 같습니다:
1. Certbot 설치:
Certbot은 Let's Encrypt 인증서를 효과적으로 관리할 수 있는 도구입니다. 다음 명령을 사용하여 Certbot을 설치합니다:
90일간 사용할 수 있으며 30일전 부터 갱신 할 수 있다.
bashCopy code
sudo yum install certbot python2-certbot-nginx
# 남은 기간확인
sudo certbot certificates
2. 방화벽 설정:
80(http), 443(https) 모두 열어야 합니다.
firewall-cmd --list-all 명령어로 열린 포트를 확인 할 수 있습니다.
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --permanent --zone=public --add-port=443/tcp
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
3. SSL 인증서 발급:
Certbot을 사용하여 SSL 인증서를 발급합니다. 도메인 이름을 실제 도메인으로 교체해 주세요.
중간에 이메일 등록을 받습니다. 해당 메일 계정으로 갱신 알림메일을 보내 줍니다.
sudo certbot certonly --nginx -d example.com -d www.example.com
위 명령을 실행하면 Certbot은 Nginx 구성을 자동으로 감지하고 도메인에 대한 SSL 인증서를 발급합니다.
발급된 인증서는 /etc/letsencrypt/live/example.com/ 디렉토리에 저장됩니다.
4. Nginx 구성 수정:
Nginx의 설정 파일을 수정하여 새로운 SSL/TLS 인증서를 사용하도록 지정합니다.
80으로 들어오면 https 프로토콜로 리다이렉트 시킵니다.
server {
listen 80;
server_name sample.com www.sample.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name sample.com www.sample.com;
ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem;
# 기본 인코딩 설정
charset utf-8;
access_log /var/log/nginx/admin.access.log main;
error_log /var/log/nginx/admin.error.log warn;
location / {
proxy_redirect off;
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;
# 프록시 연결 설정.
proxy_pass <http://127.0.0.1:8080/>;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
~
5. Nginx 구성 테스트 및 재시작:
Nginx 구성을 테스트하고 오류가 없는지 확인한 후, Nginx를 재시작하여 변경 사항을 적용합니다:
sudo nginx -t
sudo systemctl restart nginx