記錄一份生產環境常用的 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-jit | PCRE 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,便於原參數重建。make && make install,Nginx 本身無需升級。