Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Apache 啟用 SSL (HTTPS) 完整教程:OpenSSL 產生金鑰對、申請憑證、配置 httpd.conf

編輯:關於伺服器

前置條件

步驟 1:產生私鑰與 CSR (憑證簽署請求)

openssl req -new -nodes -keyout private.key -out public.csr

依提示填寫:

  • Country Name (2 字代碼):**CN** (中國)。
  • State/Province、Locality、Organization、Organizational Unit。
  • Common Name (CN):**完整域名 (FQDN),如 www.example.com**,必須精確匹配。
  • Email、Challenge Password (可留空)、Optional Company Name。

步驟 2:提交 CSR 申請憑證

將 public.csr 內容貼至 CA 申請頁面 (如 demo.sheca.com 免費 15 天測試憑證),下載簽署後的憑證 public.der (或 .crt/.pem)。

步驟 3:部署憑證與私鑰

# 放置於 Apache 可讀目錄
/etc/ssl/crt/public.der
/etc/ssl/crt/private.key

步驟 4:修改 httpd.conf 啟用 HTTPS

# 載入 SSL 模組 (若未預設載入)
LoadModule ssl_module modules/mod_ssl.so

# 監聽 443
Listen 443


    DocumentRoot "/var/www/html"
    ServerName www.example.com

    SSLEngine on
    SSLCertificateFile /etc/ssl/crt/public.der
    SSLCertificateKeyFile /etc/ssl/crt/private.key
    # 若有中繼 CA
    # SSLCertificateChainFile /etc/ssl/crt/ca_bundle.crt

步驟 5:重啟驗證

apachectl stop
apachectl startssl  # 或 apachectl start (現代版整合啟動)
# 瀏覽器訪問 https://www.example.com 驗證綠鎖

注意事項

  • 私鑰 private.key **嚴禁洩露**,權限 chmod 600、擁有者 root:root。
  • 生產環境請向受信 CA (DigiCert, GlobalSign, Let's Encrypt 等) 申請正式憑證。
  • 現代配置建議啟用 SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1、SSLCipherSuite HIGH:!aNULL:!MD5:!3DES、SSLHonorCipherOrder on、HSTS 標頭。
Copyright © Windows教程網 All Rights Reserved