nginx最新版编译(1.26.0)
1.下载nginx源码包
https://nginx.org/en/download.html
https://nginx.org/download/
2.下载编译nginx依赖包,可根据自己需求进行下载
#pcre(处理正则表达式) http://downloads.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip #zlib(Nginx 使用 zlib 来实现对 HTTP 响应内容的压缩,以提高网络传输效率和性能) https://www.zlib.net/zlib-1.3.1.tar.gz #openssl(提供 SSL/TLS 支持,保通过 HTTPS 协议进行的网络通信的安全性) https://www.openssl.org/source/openssl-3.3.0.tar.gz #headers-more-nginx-module(扩展了 Nginx 的头部处理功能) https://github.com/openresty/headers-more-nginx-module/archive/refs/tags/v0.36.zip #nginx-http-flv-module(用于实时视频流的传输和播放) https://github.com/winshining/nginx-http-flv-module/archive/refs/tags/v1.2.11.zip
3.目录结构安排
[root@ks-devops base-new]# tree -L 2 . |-- nginx #用来作为nginx当前配置目录,并且存放对应解压后的依赖包 | |-- headers-more-nginx-module-0.36 | |-- nginx-1.26.0 | |-- nginx-http-flv-module-1.2.11 | |-- openssl-3.3.0 | |-- pcre-8.45 | `-- zlib-1.3.1 `-- nginx_depend_package #用来存放nginx相关tar包,可忽略 |-- headers-more-nginx-module-0.36.zip |-- nginx-1.26.0.tar.gz |-- nginx-http-flv-module-1.2.11.zip |-- nginx-http-flv-module-master.zip |-- openssl-3.3.0.tar.gz |-- pcre-8.45.zip `-- zlib-1.3.1.tar.gz
3.进入配置编译目录
cd base-new/nginx/nginx-1.26.0
4.执行配置
./configure --prefix=/data/service/nginx \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_ssl_module \ --with-http_mp4_module \ --with-stream \ --with-http_realip_module \ --with-http_v2_module \ --with-http_sub_module \ --with-pcre=../pcre-8.45 \ --with-zlib=../zlib-1.3.1 \ --with-openssl=../openssl-3.3.0 \ --add-module=../nginx-http-flv-module-1.2.11 \ --add-module=../headers-more-nginx-module-0.36
5.执行编译
make
6.编译报错解决
6.1 在make的时候产生报错,报错信息如下: && if [ -f Makefile ]; then make clean; fi \ && ./config --prefix=/app/dockerfile/base-new/nginx/nginx-1.26.0/../openssl-3.3.0/.openssl no-shared no-threads \ && make \ && make install_sw LIBDIR=lib Can't locate IPC/Cmd.pm in @INC (@INC contains: /app/dockerfile/base-new/nginx/openssl-3.3.0/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /app/dockerfile/base-new/nginx/openssl-3.3.0/external/perl/Text-Template-1.56/lib) at /app/dockerfile/base-new/nginx/openssl-3.3.0/util/perl/OpenSSL/config.pm line 19. BEGIN failed--compilation aborted at /app/dockerfile/base-new/nginx/openssl-3.3.0/util/perl/OpenSSL/config.pm line 19. Compilation failed in require at /app/dockerfile/base-new/nginx/openssl-3.3.0/Configure line 23. BEGIN failed--compilation aborted at /app/dockerfile/base-new/nginx/openssl-3.3.0/Configure line 23. make[1]: *** [../openssl-3.3.0/.openssl/include/openssl/ssl.h] 错误 2 make[1]: 离开目录“/app/dockerfile/base-new/nginx/nginx-1.26.0” make: *** [build] 错误 2 6.2 错误说明: 错误表明在执行编译过程中缺少了 IPC::Cmd 模块,导致 Perl 脚本无法执行。 6.3 解决方法: (1)安装 Perl 模块 IPC::Cmd: yum install perl-IPC-Cmd (2)如果成功安装,将会输出 "IPC::Cmd is installed" perl -MIPC::Cmd -e 'print "IPC::Cmd is installed\n";' (3)重新执行编译步骤
make
7.编译安装
make install
8.去configure --prefix=/data/service/nginx目录查看,可以看到如下目录结构,说明编译安装成功
[root@ks-devops service]# tree -L 3 . |-- nginx | |-- conf | | |-- fastcgi.conf | | |-- fastcgi.conf.default | | |-- fastcgi_params | | |-- fastcgi_params.default | | |-- koi-utf | | |-- koi-win | | |-- mime.types | | |-- mime.types.default | | |-- nginx.conf | | |-- nginx.conf.default | | |-- scgi_params | | |-- scgi_params.default | | |-- uwsgi_params | | |-- uwsgi_params.default | | `-- win-utf | |-- html | | |-- 50x.html | | `-- index.html | |-- logs | `-- sbin | `-- nginx
9.打包成tar.gz,可以放到其他的x86 linux机器上使用,也可以制作成nginx的docker镜像,但需要注意的是安装目录,普通安装需要安装在/data/service/下,容器内也是这个目录
cd /data/service/ && tar zcf nginxks-1.26.0.tar.gz nginx && mv nginxks-1.26.0.tar.gz /app/dockerfile/base-new/
10.参考文档
https://blog.csdn.net/x_iya/article/details/75220797 https://www.cnblogs.com/shuiche/p/14377328.html