nginx 编译错误 the HTTP rewrite module requires the PCRE library

Nginx 2020-06-08 阅读 4492 评论 0

问题描述

编译 nginx 1.19.0,使用 ./configure --prefix=/opt/nginx-1.19.0,出现如下错误。

checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./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=<path> option.

解决方法

需要安装 pcre。

1. Mac OS

在官网 http://www.pcre.org/ 中下载 pcre,比如 pcre-8.44.zip,运行:

$ unzip pcre-8.44.zip
$ cd pcre-8.44
$ pwd
/Users/cpm/Downloads/packages/pcre-8.44

注意不用编译 pcre,下面 configure nginx 的时候,会自动编译 pcre。

复制 pcre-8.44.zip 解压的源代码路径,重新编译 nginx,运行

./configure --prefix=/opt/nginx-1.19.0 --with-pcre=/Users/cpm/Downloads/packages/pcre-8.44

2. Ubuntu/Debian

  • 使用第1步 Mac OS 的方法
  • 在 https://pkgs.org/search/?q=libpcre 页面中,找到与操作系统相对应的 libpcre 和 libpcre-dev 包,并下载安装。
  • 或者使用 apt-get 命令
sudo apt-get install libpcre3-dev

3. RHEL / CentOS

  • 使用第1步 Mac OS 的方法
  • 在 https://pkgs.org/search/?q=pcre 页面中,找到与操作系统相对应的 pcre 和 pcre-dev 包,并下载安装。
  • 或者使用 yum 命令
sudo yum install pcre-devel
最后更新 2020-06-09