HTTPS – Ubuntu – 安裝 Let’s Encrypt 免費90天的 SSL
除了可以在 SSL For Free 這個網站上手動申請,也可以透過指令的方式來安裝,好處是申請比較快,不需要透過滑鼠按來按去。憑證 90 天到期以後,也只需要更新憑證就好,不需要手動重新上傳。
先在 Linux 上安裝
apt-get install letsencrypt letsencrypt certonly
如果 Server 正在運作,那會跳出因為 apache2 現在監聽了 80 port,須要先停止後再重新嘗試。service apache2 stop 後重新操作。接著輸入 domain,可用空格或 / 區隔不同的網域:
www.domain.com domain.com
至於能不能用 *domain.com 呢?我記得是不可以,但我沒有測試。成功後會告訴你證書 pem 的存放位置如 /etc/letsencrypt/live/domain.org/fullchain.pem、過期日
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/domain.org/fullchain.pem. Your cert will expire on 2018-06-18. To obtain a new version of the certificate in the future, simply run Let's Encrypt again. - If you like Let's Encrypt, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
因為剛剛關閉伺服器,所以記得啟用 service apache2 start,並前往設定 /etc/apache2/sites-available/default-ssl.conf,添加需要的證書路徑、私鑰、中繼憑證授權單位 (CA) 。中繼憑證授權單位 SSLCertificateChainFile 務必要添加,否則在不同的瀏覽器有些會認為證書是不安全的,例如 Firefox。
<IfModule mod_ssl.c> NameVirtualHost *:443 <VirtualHost *:443> SSLEngine on DocumentRoot /var/www/html/dennings-kill-queue <----指定 ServerName kill-queue.dennings.org <----指定 ServerAlias www.kill-queue.dennings.com <----指定 ServerAdmin info@dennings.org <----指定 SSLCertificateFile /etc/letsencrypt/live/domain.org/cert.pem <----指定路徑 SSLCertificateKeyFile /etc/letsencrypt/live/domain.org/privkey.pem <----指定路徑 SSLCertificateChainFile /etc/letsencrypt/live/domain.org/chain.pem <----指定路徑 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> <Directory "/var/www/html/dennings-kill-queue"> <----指定 AllowOverride All </Directory> </VIrtualHost> </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
修改好後重啟 service apache2 restart 來更新設定。
river
2019-05-17 - 17:00
請問為什麼按您的設定, 443 仍無法啟動? 我使用 netstat -nlpt 檢查.