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

Nginx 編譯參數記錄:HTTP/2、OpenSSL 1.1.1、模組裁剪與第三方模組整合

編輯:Linux 教學

記錄一份生產環境常用的 Nginx 編譯配置,涵蓋核心模組精簡、OpenSSL 版本綁定、第三方模組(echo、subs_filter、limit_req2)整合,作為未來重建環境的參考基線。

編譯命令完整版


./configure \
    --user=www --group=www \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_gzip_static_module \
    --with-http_sub_module \
    --with-http_stub_status_module \
    --with-threads \
    --with-file-aio \
    --with-pcre-jit \
    --with-openssl=/usr/local/src/openssl-1.1.1w \
    --with-openssl-opt='enable-tls1_3 enable-weak-ssl-ciphers' \
    --without-http_autoindex_module \
    --without-http_geo_module \
    --without-http_map_module \
    --without-http_memcached_module \
    --without-http_scgi_module \
    --without-http_uwsgi_module \
    --without-mail_pop3_module \
    --without-mail_imap_module \
    --without-mail_smtp_module \
    --add-module=/usr/local/src/echo-nginx-module-0.63 \
    --add-module=/usr/local/src/ngx_http_substitutions_filter_module-master \
    --add-module=/usr/local/src/ngx_http_limit_req_module-master \
    --prefix=/usr/local/nginx

關鍵參數解析

參數用途
--with-http_v2_module啟用 HTTP/2(舊版為 --with-http_spdy_module,SPDY 已廢棄)
--with-openssl=PATH靜態鏈接指定 OpenSSL 源碼,支援 TLS 1.3、ALPN、ChaCha20-Poly1305
--with-openssl-opt傳遞給 OpenSSL 的編譯選項,啟用 TLS 1.3 等特性
--with-http_sub_module內建 sub_filter,支援響應體字串替換
--add-module=...動態載入第三方模組:echo(調試)、subs_filter(多模式替換)、limit_req2(增強限流)
--without-http_*_module裁剪無用模組,減小二進制體積、降低攻擊面
--with-pcre-jitPCRE JIT 編譯加速正則匹配

編譯與安裝


make -j$(nproc)
make install
# 二進制位置:/usr/local/nginx/sbin/nginx

驗證模組載入


/usr/local/nginx/sbin/nginx -V 2>&1 | grep -o -- '--with-http_[^ ]*'
/usr/local/nginx/sbin/nginx -V 2>&1 | grep -o -- '--add-module=[^ ]*'

升級維護建議

  • 保留 config.status 或將上述命令存為 build_nginx.sh,便於原參數重建。
  • OpenSSL 發布安全更新時,僅需替換源碼目錄重新 make && make install,Nginx 本身無需升級。
  • 第三方模組遷移至 Git submodule 管理,鎖定具體 commit,保證可重現構建。
Copyright © Windows教程網 All Rights Reserved