「Nginx」CentOS7.6操作系统下通过源码安装Nginx问题汇总

没有配置pcre库

1
2
3
4
./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库或者通过配置项–with-pcre指定pcre库源码路径来解决此问题。如果不需要启用此模块,则可以使用配置项–without-http_rewrite_module声明不启用HttpRewrite模块。

没有配置zlib库

1
2
3
4
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

  可以通过安装zlib库或者通过配置项–with-zlib指定zlib库源码路径来解决此问题。如果不需要启用此模块,则可以使用配置项–without-http_gzip_module声明不启用Gzip模块。

没有配置openssl库

1
2
3
4
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

  nginx默认是不启用HttpSsl模块的,如果在配置中指定了–with-http_ssl_module,则需要安装openssl库或者通过配置项–with-openssl指定openssl库源码路径来解决此问题。

指定的库路径不正确

1
2
3
4
5
6
7
8
9
10
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-1.17.1'
cd ~/pcre-8.43 \
&& if [ -f Makefile ]; then make distclean; fi \
&& CC="cc" CFLAGS="-O2 -fomit-frame-pointer -pipe " \
./configure --disable-shared
/bin/sh: line 0: cd: /root/pcre-8.43: No such file or directory
make[1]: *** [/root/pcre-8.43/Makefile] Error 1
make[1]: Leaving directory `/root/nginx-1.17.1'
make: *** [build] Error 2

  终端输入make && make install后,出现了以上错误。根据错误提示内容中的**/root/pcre-8.43: No such file or directory可以看出这个路径是不存在的。通过ls /root**发现确实是不存在此文件,因此需要重新在终端中使用./configure并重新配置相应的正确路径。

无效编译器

1
2
3
4
configure: error: Invalid C++ compiler or C++ compiler flags
make[1]: *** [/root/pcre-8.43/Makefile] Error 1
make[1]: Leaving directory `/root/nginx-1.17.1'
make: *** [build] Error 2

  根据错误提示可以看出,编译的时候没有找到合适的编译器。可以通过**yum install gcc gcc-c++**安装编译时需要的编译器。

找不到openssl/ssl.h文件

1
2
3
4
5
6
7
8
9
In file included from src/core/ngx_core.h:83:0,
from src/core/nginx.c:9:
src/event/ngx_event_openssl.h:15:25: fatal error: openssl/ssl.h: No such file or directory
#include <openssl/ssl.h>
^
compilation terminated.
make[1]: *** [objs/src/core/nginx.o] Error 1
make[1]: Leaving directory `/root/nginx-1.17.1'
make: *** [build] Error 2

  这个错误比较神奇,我也没进行深究,只是在./configure阶段使用的~/XXX作为路径配置了–with-openssl的配置项。出现这个问题后,我把nginx源码的文件夹统统删掉后,重新解压后将–with-openssl配置为绝对路径后就没问题了。