HTTP 明文傳輸帳密、Cookie、敏感資料,極易遭中間人竊聽竄改。SSL/TLS(HTTPS)提供加密傳輸、伺服器身分驗證、完整性保護,現為網站標配。本文示範從源碼編譯 Apache 1.3.x + mod_ssl + OpenSSL 的經典流程(現代部署建議直接使用發行版套件 apt install apache2 libapache2-mod-ssl 或 dnf install httpd mod_ssl)。
| 元件 | 版本 | 說明 |
|---|---|---|
| Apache | 1.3.24 | 舊版穩定分支 |
| mod_ssl | 2.8.8-1.3.24 | 必須與 Apache 版本嚴格對應 |
| OpenSSL | 0.9.6c | 建議升級至 1.1.1/3.0 長期支援版 |
cd /usr/local/src
tar xzf openssl-0.9.6c.tar.gz
cd openssl-0.9.6c
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl
make && make test && make install
cd /usr/local/src
tar xzf mod_ssl-2.8.8-1.3.24.tar.gz
cd mod_ssl-2.8.8-1.3.24
./configure --with-apache=/usr/local/src/apache_1.3.24 --with-ssl=/usr/local/ssl
cd /usr/local/src/apache_1.3.24
./configure \
--prefix=/usr/local/apache \
--enable-rule=SHARED_CORE \
--enable-module=ssl \
--enable-shared=ssl
make
cd /usr/local/src/apache_1.3.24
make certificate TYPE=custom
# 互動式輸入兩組資訊:
# 第一組:建立臨時 CA(Common Name 可隨意)
# 第二組:正式伺服器憑證(Common Name = 伺服器 FQDN,如 www.example.com)
make install
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl startssl
https://yourdomain.com → 80 埠 HTTPhttps://yourdomain.com → 443 埠 HTTPS,瀏覽器顯示鎖頭圖示openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 檢視憑證鏈# Ubuntu/Debian
apt update && apt install -y apache2 certbot python3-certbot-apache
a2enmod ssl rewrite headers
certbot --apache -d example.com -d www.example.com
# 自動續期已納入 systemd timer
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5:!3DES
SSLHonorCipherOrder on
SSLCompression off
SSLSessionTickets off
# HSTS(謹慎啟用,確保所有子域皆支援 HTTPS)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# OCSP Stapling
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
從源碼編譯 mod_ssl 能深入理解 Apache SSL 模組載入機制,但生產環境請優先使用發行版套件與自動化憑證工具(Certbot/acme.sh),確保持續獲得安全更新與憑證續期。核心原則:強協議、強加密套件、HSTS、OCSP Stapling、定期掃描(SSL Labs/Qualys)。