安裝

安裝

我正在嘗試在我的 apache2 網路伺服器上設定 SSL,但似乎根本不起作用。

我已按照教學課程使用 openssl 建立憑證檔案並/etc/apache2/sites-available/default-ssl.conf正確配置。

每次我嘗試使用 https 開啟網站時,我的瀏覽器都會因安全問題而拒絕連線。它說我沒有正確配置我的網站。

在 my 中,/var/log/apache2/error.log我收到警告,表示我的伺服器憑證不包含與伺服器名稱相符的 ID。

[Mon Apr 10 11:03:24.041813 2017] [mpm_prefork:notice] [pid 1222] AH00169: caught SIGTERM, shutting down
[Mon Apr 10 11:03:30.566578 2017] [ssl:warn] [pid 661] AH01909: 127.0.0.1:443:0 server certificate does NOT include an ID which matches the server name
[Mon Apr 10 11:03:31.579088 2017] [ssl:warn] [pid 1194] AH01909: 127.0.0.1:443:0 server certificate does NOT include an ID which matches the server name
[Mon Apr 10 11:03:31.592958 2017] [mpm_prefork:notice] [pid 1194] AH00163: Apache/2.4.25 (Raspbian) OpenSSL/1.0.2k configured -- resuming normal operations
[Mon Apr 10 11:03:31.593136 2017] [core:notice] [pid 1194] AH00094: Command line: '/usr/sbin/apache2'

您對如何解決這個問題有什麼想法嗎?謝謝您的關注!

答案1

好吧,我注意到這篇文章最近被瀏覽得很頻繁,所以似乎很多人都面臨著和我一樣的問題。如果是這樣,那麼這可能對您有幫助。

我按照簡單的逐步教學為我的網頁伺服器建立了 SSL 認證。像許多教程一樣,我遵循的教程的結果是使用 OpenSSL 的自簽名憑證。是的自簽名,這就是問題所在。瀏覽器無法信任伺服器,因為它的憑證是自己簽署的。嗯,我也不會做...

憑證必須由外部值得信賴的憑證授權單位 (CA) 簽署。所以我偶然發現讓我們加密它可以為您完成所有工作,並且更容易設置,而且最好的是:它完全免費。

安裝

1) 刪除使用 OpenSSL 建立的舊 ssl 憑證文件

2) 開啟向後移植以在 Debian 上取得 certbot 用戶端。您應該知道,這將為未完成的軟體打開一個漏洞!僅當您了解自己在做什麼時才安裝軟體包。

echo 'deb http://ftp.debian.org/debian jessie-backports main' | sudo tee /etc/apt/sources.list.d/backports.list

3)更新你的Linux系統

sudo apt-get update

4)安裝證書機器人

sudo apt-get install python-certbot-apache -t jessie-backports

5)設定apache ServerName和ServerAlias

sudo nano /etc/apache2/sites-available/000-default.conf

6) 編輯apache設定檔

<VirtualHost *:80>
    . . .
    ServerName example.com
    ServerAlias www.example.com
    . . .
</VirtualHost>

7) 檢查語法是否正確

sudo apache2ctl configtest

8) 如果設定檔看起來沒問題,請重新啟動 apache 伺服器

sudo systemctl restart apache2

9) 使用 certbot 設定憑證並依照螢幕上的指示操作。

sudo certbot --apache

更新

Let's Encrypt 的所有憑證的有效期為 3 個月。若要更新您可以手動運行

sudo certbot renew

或將此服務自動化為 cron 作業

sudo crontab -e

並輸入以下行以在每週一凌晨 2:30 調用續訂。

. . .
30 2 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log

您可以在此處遵循更詳細的教程:https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-debian-8

答案2

就我而言,我已透過在每個相關網域的 apache ssl 設定檔中替換來解決此問題:

ServerName mydomain.com
ServerAlias www.mydomain.com

經過 :

ServerName www.mydomain.com
ServerAlias mydomain.com

因為我的憑證適用於“www.mydomain.com”而不是“mydomain.com”

完整的阿帕契文​​件:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin [email protected]
        ServerName www.mydomain.com
        ServerAlias mydomain.com
    DocumentRoot /home/mydomain.com/public_html
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|ico|png)$ \ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ \no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    <Directory />
        Options +FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /home/mydomain.com/public_html>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride All
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>


ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn
SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

答案3

如果您沒有看到其他 SSL 錯誤,並且您已嘗試在 httpd.conf 檔案中設定“LogLevel debug”,則此錯誤訊息也可能表示 httpd.conf 檔案中缺少“Listen 443”。

答案4

我最近遇到了這個問題,當時我的自簽名憑證過期了。我用谷歌搜尋並剛剛複製了從一個網站創建新證書的命令。

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/apache2/ssl/apache.crt

在我的 apache 設定檔中:/etc/apache2/sites-available/default-ssl.conf。證書檔案和密鑰檔案是指以下檔案名稱。

    SSLCertificateFile  /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key

因此,在我的例子中看到的錯誤更容易修復,只需在建立 ssl 憑證時提供憑證金鑰檔案的正確位置即可。

所以,這是我應該正確使用和輸入的命令。

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

相關內容