
Nếu máy chủ web của bạn không sử dụng bất cứ Control Panel nào, và sử dụng LAMP Stack thuần thì trong bài viết này tối sẽ hướng dẫn bạn Cài đặt SSL Let’s Encrypt với Certbot trên APACHE. Xin mời các bạn theo dõi
Lưu ý: Để cài đặt và cấp phát chứng chỉ SSL. Bắt buộc tên miền cài SSL phải được trỏ về IP máy chủ VPS
Bước 1: SSH vào máy chủ
Đây là điều hiển nhiên rồi. Để cài được SSL thì bạn phải SSH vào máy chủ VPS đó
Bước 2: Cài đặt Certbot
- Đối với CentOS
yum -y install epel-release
yum -y install certbot python2-certbot-apache mod_ssl

- Đối với Ubuntu
apt install certbot python3-certbot-apache
Bước 3: Yêu cầu cấp phát chứng chỉ SSL
Để yêu cầu cấp phát chứng chỉ bạn chạy lệnh với cú pháp sau. Lưu ý bạn hãy thay tên miền caissl.com của tôi bằng tên miền bạn muốn cái SSL
certbot --apache -d caissl.com -d www.caissl.com
Sau đó khi được hỏi nhập vào thông tin. Bạn hãy nhập vào thông tin của bạn.
[root@template conf.d]# certbot --apache -d caissl.com -d www.caissl.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): admin@caissl.com (Nhập email của bạn)
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y (Nhấn Y để đồng ý điều khoản)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N (Nhấn N để từ chối các thông tin, tin tức từ letsencrypt và Certbot )
Account registered.
Requesting a certificate for caissl.com and www.caissl.com
Performing the following challenges:
http-01 challenge for caissl.com
http-01 challenge for www.caissl.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/caissl.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/caissl.com-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/caissl.com-le-ssl.conf
Redirecting vhost in /etc/httpd/conf.d/caissl.com.conf to ssl vhost in /etc/httpd/conf.d/caissl.com-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://caissl.com and
https://www.caissl.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/caissl.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/caissl.com/privkey.pem
Your certificate will expire on 2021-04-23. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again with the "certonly" option. To non-interactively
renew *all* of your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Như vậy đã cài đặt thành công SSL thông qua Certbot, đường đẫn lưu file chứng chỉ của website sẽ nằm tại đường dẫn tương ứng.
/etc/letsencrypt/live/caissl.com/fullchain.pem
/etc/letsencrypt/live/caissl.com/privkey.pem
Chứng chỉ Let’s Encrypt chỉ có hiệu lực trong 90 ngày, các bạn có thể gia hạn thủ công hoặc thiết lập cronjob để làm việc đó như sau
- Gia hạn thủ công
certbot renew --dry-run
Để gia hạn chứng chỉ SSL tự động. Bạn nhập lệnh crontab -e
sau đó dán vào đoạn mã sau.
export VISUAL=nano; crontab -e
Sau đó sao chép nội dung bên dưới vào
00 6 * * * /usr/bin/certbot renew --quiet
Chú thích: Cronjob này có nghĩa là cứ đúng 6:00 AM nó sẽ check chứng chỉ, nếu chứng chỉ hết hạn sẽ tự động gia hạn. Ngược lại, nếu còn hạn sẽ không thực hiện gia hạn.
