./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=option.
Nginx 的 HTTP Rewrite 模組依賴 PCRE (Perl Compatible Regular Expressions) 庫進行正則表達式處理。系統缺少 PCRE 開發套件或未指定來源路徑。
wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz tar -zxvf pcre-8.45.tar.gz # 解壓至 /usr/local/src/pcre-8.45 或任意目錄
./configure \ --prefix=/usr/local/nginx \ --with-pcre=/usr/local/src/pcre-8.45 \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_gzip_static_module
關鍵點:--with-pcre 參數後接的是 PCRE 原始碼目錄,而非安裝目錄。Nginx 會內建編譯 PCRE,不依賴系統庫。
make && make install
yum install -y pcre-devel ./configure --prefix=/usr/local/nginx
apt-get install -y libpcre3-dev ./configure --prefix=/usr/local/nginx
/usr/local/nginx/sbin/nginx -V # 輸出應包含:--with-pcre=... 或 --with-pcre=system
| Nginx 模組 | 所需庫 | 開發包 |
|---|---|---|
| HTTP Rewrite | PCRE | pcre-devel / libpcre3-dev |
| HTTP SSL | OpenSSL | openssl-devel / libssl-dev |
| HTTP Gzip | zlib | zlib-devel / zlib1g-dev |
| HTTP/2 | OpenSSL 1.0.2+ | 同上 |
#!/bin/bash
NGINX_VER="1.24.0"
PCRE_VER="8.45"
ZLIB_VER="1.2.13"
OPENSSL_VER="1.1.1w"
cd /usr/local/src
wget -q https://nginx.org/download/nginx-${NGINX_VER}.tar.gz
wget -q https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz
wget -q https://zlib.net/zlib-${ZLIB_VER}.tar.gz
wget -q https://www.openssl.org/source/openssl-${OPENSSL_VER}.tar.gz
tar -xzf nginx-${NGINX_VER}.tar.gz
tar -xzf pcre-${PCRE_VER}.tar.gz
tar -xzf zlib-${ZLIB_VER}.tar.gz
tar -xzf openssl-${OPENSSL_VER}.tar.gz
cd nginx-${NGINX_VER}
./configure \
--prefix=/usr/local/nginx \
--with-pcre=../pcre-${PCRE_VER} \
--with-zlib=../zlib-${ZLIB_VER} \
--with-openssl=../openssl-${OPENSSL_VER} \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module
make -j$(nproc) && make install