在apache2上設定HTTPS,無需購買域名

在apache2上設定HTTPS,無需購買域名

我已經在 Debian 9 Stretch(Raspian 因為是樹莓派)上使用 apache2 成功建立了一個網站(2 個虛擬主機,我在同一網域中還有另一個網站)。

它儲存在以下路徑:/var/www/html/www.mysite.ddns.net/www/。我可以透過以下連結訪問它:mysite.ddns.net

現在我想設定一個 https 連接,所以我嘗試使用 Let's encrypt using證書機器人

不幸的是,當我運行命令時sudo certbot --apache,它給了我這個錯誤:

Obtaining a new certificate
Performing the following challenges:
Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.
Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.

哪裡有問題?

答案1

自動certbot --apache模式可能無法運作,因為您網站的 URL 與您在 Apache 中使用的根目錄不完全相符。

一種選擇是手動指定將用於憑證的網域名稱以及 Web 伺服器的根目錄。

certbot certonly --webroot -w /var/www/html/www.mysite.ddns.net/www/ -d mysite.ddns.net

此命令用作/var/www/html/www.mysite.ddns.net/www/Web 伺服器的根目錄。 Certbot 會將暫存檔案(對於您的網域來說是唯一的)放置在名稱所在的目錄中.well_known,然後嘗試讀取位於 的這些檔案http://mysite.ddns.net/.well_known。如果找到這些文件,您將獲得證書。

證書文件將放置在/etc/letsencrypt/live/mysite.ddns.net/.

若要將 Apache 設定為使用這些證書,您可以使用下列命令將它們新增至 Apache 網站設定:

SSLEngine on
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.ddns.net/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/mysite.ddns.net/fullchain.pem

請務必運作a2enmod ssl以確保 Apache 的 SSL 模組已啟用。

還有一些更多的 Certbot 範例可以查看使用者指南

相關內容