Linux编译安装nginx时的依赖安装 - 小众知识

Linux编译安装nginx时的依赖安装

2022-08-13 15:08:46 苏内容
  标签: Linux/nginx
阅读:5864

nginx的环境依赖说明

1.gcc的安装:安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:


#CentOS:

 

yum install gcc-c++

 

#Ubuntu:

(以下选择一种)

 

1.    sudo apt-get -y install build-essential    #安装包含gcc c++编译器的包

2.    sudo apt-get -y install gcc    #安装gcc编译器

2.PCRE pcre-devel 安装:CRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。


        未安装pcre库的报错


./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.

 

./configure: 错误:HTTP 重写模块需要 PCRE 库。

您可以使用 --without-http_rewrite_module 禁用该模块

选项,或者将 PCRE 库安装到系统中,或者构建 PCRE 库

使用 --with-pcre=<path> 选项从 nginx 的源静态地获取。

          解决办法


#CentOS:

 

yum install -y pcre pcre-devel

 

#Ubuntu:

 

sudo apt-get update

sudo apt-get -y install libpcre3 libpcre3-dev

3.zlib 安装:zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。


        未安装zlib 库的报错


./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.

 

./configure: 错误:HTTP gzip 模块需要 zlib 库。

您可以使用 --without-http_gzip_module 禁用该模块

选项,或者将zlib库安装到系统中,或者构建zlib库

使用 --with-zlib=<path> 选项从 nginx 源静态地获取。

          解决办法


#CentOS:

 

yum install -y zlib zlib-devel

 

#Ubuntu:

 

sudo apt-get -y install zlib1g-dev

4.OpenSSL 安装:OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。


        未安装OpenSSL 库的报错


./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.

 

./configure: 错误:SSL 模块需要 OpenSSL 库。

您可以不启用模块,也可以安装 OpenSSL 库

进入系统,或者从源代码静态构建 OpenSSL 库

通过使用 --with-openssl=<path> 选项与 nginx 一起使用。

         解决办法


#CentOS:

 

yum install -y openssl openssl-devel

 

#Ubuntu:

 

sudo apt-get -y install openssl libssl-dev

5.libraries库安装:

          未安装libraries库的报错


./configure: error: the HTTP XSLT module requires the libxml2/libxslt

libraries. You can either do not enable the module or install the libraries.

 

./configure: 错误:HTTP XSLT 模块需要 libxml2/libxslt

图书馆。 您可以不启用该模块或安装库。

         解决办法


#Ubuntu:

 

sudo apt-get -y install libxml2 libxml2-dev libxslt-dev

sudo apt-get -y install libgd2-xpm libgd2-xpm-dev

 6.GD库安装:

          未安装GD库的报错


./configure: error: the HTTP image filter module requires the GD library.

You can either do not enable the module or install the libraries.

 

./configure: 错误:HTTP 图像过滤器模块需要 GD 库。

您可以不启用该模块或安装库。

       解决办法


#CentOS:

 

yum install gd gd-devel

 

#Ubuntu:

 

sudo apt-get install -y libgd-dev

出现以下内容即安装完成

 

7.安装

 输入make 进行编译,编译完成出现以下界面则成功:




 输入make install安装,以下安装完成  



Nginx安装时出现In function ‘ngx_murmur_hash2’等错误

错误信息1:

src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:

src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]

         h ^= data[2] << 16;

         ~~^~~~~~~~~~~~~~~~

src/core/ngx_murmurhash.c:38:5: note: here

     case 2:

     ^~~~

src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]

         h ^= data[1] << 8;

         ~~^~~~~~~~~~~~~~~

src/core/ngx_murmurhash.c:40:5: note: here

     case 1:

     ^~~~

cc1: all warnings being treated as errors

make[1]: *** [objs/Makefile:432: objs/src/core/ngx_murmurhash.o] Error 1

 

原因:将警告信息当作错误信息进行了处理

解决方法:使用编辑器打开nginx/objs/Makefile,删除CFLAGS中的-Werror,如图所示;



重新进行make操作即可


错误信息2:

src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:

src/os/unix/ngx_user.c:35:7: error: ‘struct crypt_data’ has no member named ‘current_salt’

     cd.current_salt[0] = ~salt[0];

       ^

make[1]: *** [objs/Makefile:712: objs/src/os/unix/ngx_user.o] Error 1


原因:源代码问题

解决方法:修改ngx_user.c



注释掉蓝线标注的代码

重新make即可成功 



我使用WDCP面板,在lanmp.sh脚本运行的时候,选择了nginx环境。 跑了半天,就报这个错误

src/core/ngx_murmurhash.c: In function 'ngx_murmur_hash2':src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
         h ^= data[2] << 16;
         ~~^~~~~~~~~~~~~~~~src/core/ngx_murmurhash.c:38:5: note: here     case 2:
     ^~~~src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
         h ^= data[1] << 8;
         ~~^~~~~~~~~~~~~~~src/core/ngx_murmurhash.c:40:5: note: here     case 1:
复制

网上说的很清楚了,是因为error的问题,我在objs/Makefile文件中的确看到了CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused -Werror,网上的说法是去掉这个就可以了,但是因为Makefile文件是自动生成的,能不能在生成的时候,就不要加入-Werror的参数呢? 答案是可以的 在./configure加入--with-cc-opt=-Wno-error参数即可,比如: ./configure --with-cc-opt=-Wno-error 这是初步的解决方案,实际上,还可以这样,在运行lamp.sh脚本前,修改lib/nginx.sh脚本中的14行也可以。 (我这里因为是docker的镜像文件,所以直接用脚本了。)


扩展阅读
相关阅读
© CopyRight 2010-2021, PREDREAM.ORG, Inc.All Rights Reserved. 京ICP备13045924号-1