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

DirectAdmin 啟用 HTTP/2 支援完整教學:自編譯 OpenSSL 1.0.2+ 與 nghttp2

編輯:Linux 教學

DirectAdmin 面板預設尚未在介面提供 HTTP/2 啟用選項,但其 custombuild 架構已內建 nghttp2 支援。本文記錄在 DirectAdmin 環境下,透過自編譯 OpenSSL 1.0.2+(支援 ALPN)並重新編譯 Apache 以啟用 HTTP/2 的完整步驟。

前置條件

  • DirectAdmin 授權有效,custombuild 版本 2.0+。
  • 系統已安裝開發工具鏈(gcc、make、perl 等)。

步驟 1:安裝支援 ALPN 的 OpenSSL 到獨立路徑

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz   # 建議使用 1.0.2 系列最新版
tar xzf openssl-1.0.2u.tar.gz
cd openssl-1.0.2u
./config --prefix=/usr/local/lib_http2 no-ssl2 no-ssl3 zlib-dynamic
make depend
make install

注意:安裝到 /usr/local/lib_http2 避免污染系統預設 OpenSSL。

步驟 2:編譯安裝 nghttp2(DirectAdmin 內建)

cd /usr/local/directadmin/custombuild
./build update
./build nghttp2

步驟 3:建立自訂 Apache 編譯配置

cd /usr/local/directadmin/custombuild
mkdir -p custom/ap2
cp -p configure/ap2/configure.apache custom/ap2/configure.apache

步驟 4:修改 custom/ap2/configure.apache

找到原有 SSL 路徑行:

"--with-ssl=/usr" \

替換為:

"--enable-http2" \
"--enable-ssl-staticlib-deps" \
"--with-ssl=/usr/local/lib_http2" \

步驟 5:重新編譯 Apache

./build apache

編譯過程約 5-15 分鐘,視 CPU 核心數而定。

步驟 6:啟用 HTTP/2 協議宣告

echo 'ProtocolsHonorOrder On'  >> /etc/httpd/conf/extra/httpd-includes.conf
echo 'Protocols h2 h2c http/1.1' >> /etc/httpd/conf/extra/httpd-includes.conf

步驟 7:重寫配置並重啟

cd /usr/local/directadmin/custombuild
./build rewrite_confs
systemctl restart httpd

驗證與已知問題

  • 驗證:curl -I --http2 https://your.domain/ 應回傳 HTTP/2 200;瀏覽器開發者工具 Network 標籤顯示 h2。
  • 已知 Bug:Apache 2.4.37 及較早版本在使用泛域名憑證(如 *.example.com)部署多子域名時,第二個子域名會連線失敗。此為 Apache 核心 Bug,升級至 2.4.38+ 或改用獨立憑證可規避。

補充:Nginx 反向代理場景

若前端使用 Nginx 反代 Apache,只需在 Nginx 啟用 HTTP/2(listen 443 ssl http2;),後端 Apache 保持 HTTP/1.1 即可,效能損耗極小且配置更簡單。

Copyright © Windows教程網 All Rights Reserved