从源代码构建定制Nginx
官方文档: 从源代码构建Nginx
基于源码,定制编译Nginx,提供了关于源码编译Nginx的示例
- 不使用外部模块编译Nginx
- 使用外部模块编译Nginx
编译环境
Nginx版本: 1.27.5
操作系统: Ubuntu 18.04
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic一.不使用外部模块编译Nginx操作步骤
演示机器
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic1.下载源码包
下载页面 https://nginx.org/en/download.html
这里下载 nginx-1.27.5 版本的源码,基于该版本构建
wget https://nginx.org/download/nginx-1.27.5.tar.gz
# 解压
tar -xzvf nginx-1.27.5.tar.gz
# 进入源码目录
cd nginx-1.27.52.安装依赖包
sudo apt install gcc libpcre3-dev zlib1g-dev make3.使用configure命令配置构建
最后会创建一个Makefile文件
根据需求定制Nginx,选项参考: https://nginx.org/en/docs/configure.html
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'成功输出
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using threads
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
4.编译安装
make
# 或者 make -j
# -j 不限制作业数量,提高编译速度
# 注意,性能不行可能会导致机器卡死编译结束
objs/src/stream/ngx_stream_upstream_least_conn_module.o \
objs/src/stream/ngx_stream_upstream_random_module.o \
objs/src/stream/ngx_stream_upstream_zone_module.o \
objs/src/stream/ngx_stream_ssl_preread_module.o \
objs/ngx_modules.o \
-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie -ldl -lpthread -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
make[1]: Leaving directory '/home/swift/nginx/nginx-1.27.5'如果需要安装,运行make install 安装即可
查看make install 安装命令,不实际安装
$ make install -n
make -f objs/Makefile install
make[1]: Entering directory '/home/swift/nginx/nginx-1.27.5'
test -d '/etc/nginx' || mkdir -p '/etc/nginx'
test -d '/usr/sbin' \
|| mkdir -p '/usr/sbin'
test ! -f '/usr/sbin/nginx' \
|| mv '/usr/sbin/nginx' \
'/usr/sbin/nginx.old'
cp objs/nginx '/usr/sbin/nginx'
test -d '/etc/nginx' \
|| mkdir -p '/etc/nginx'
cp conf/koi-win '/etc/nginx'
cp conf/koi-utf '/etc/nginx'
cp conf/win-utf '/etc/nginx'
test -f '/etc/nginx/mime.types' \
|| cp conf/mime.types '/etc/nginx'
cp conf/mime.types '/etc/nginx/mime.types.default'
test -f '/etc/nginx/fastcgi_params' \
|| cp conf/fastcgi_params '/etc/nginx'
cp conf/fastcgi_params \
'/etc/nginx/fastcgi_params.default'
test -f '/etc/nginx/fastcgi.conf' \
|| cp conf/fastcgi.conf '/etc/nginx'
cp conf/fastcgi.conf '/etc/nginx/fastcgi.conf.default'
test -f '/etc/nginx/uwsgi_params' \
|| cp conf/uwsgi_params '/etc/nginx'
cp conf/uwsgi_params \
'/etc/nginx/uwsgi_params.default'
test -f '/etc/nginx/scgi_params' \
|| cp conf/scgi_params '/etc/nginx'
cp conf/scgi_params \
'/etc/nginx/scgi_params.default'
test -f '/etc/nginx/nginx.conf' \
|| cp conf/nginx.conf '/etc/nginx/nginx.conf'
cp conf/nginx.conf '/etc/nginx/nginx.conf.default'
test -d '/var/run' \
|| mkdir -p '/var/run'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
test -d '/etc/nginx/html' \
|| cp -R html '/etc/nginx'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
make[1]: Leaving directory '/home/swift/nginx/nginx-1.27.5'查看Makefile文件
$ cat Makefile
default: build
clean:
rm -rf Makefile objs
.PHONY: default clean
build:
$(MAKE) -f objs/Makefile
install:
$(MAKE) -f objs/Makefile install
modules:
$(MAKE) -f objs/Makefile modules
upgrade:
/usr/sbin/nginx -t
kill -USR2 `cat /var/run/nginx.pid`
sleep 1
test -f /var/run/nginx.pid.oldbin
kill -QUIT `cat /var/run/nginx.pid.oldbin`
.PHONY: build install modules upgrade5.验证
可执行文件
$ ls -alh objs/nginx
-rwxrwxr-x 1 swift swift 8.7M Apr 18 02:51 objs/nginx$ ./objs/nginx -V
nginx version: nginx/1.27.5
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'问题记录
./configure 阶段
./configure: error: C compiler cc is not found
checking for OS
+ Linux 4.15.0-213-generic x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
需要安装gcc
sudo apt install gcc./configure: error: the HTTP rewrite module requires the PCRE library.
checking for getaddrinfo() ... found
checking for PCRE2 library ... not found
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
checking for PCRE library in /opt/homebrew/ ... 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.
./configure:错误:HTTP重写模块需要PCRE库。
您可以使用--without-http_rewrite_module选项禁用该模块,也可以将PCRE库安装到系统中,或者使用--with-PCRE=<path>选项使用nginx从源代码静态构建PCRE库。安装pcre library
sudo apt install libpcre3-dev./configure: error: the HTTP gzip module requires the zlib library.
checking for zlib library ... not found
./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 库。
安装
sudo apt-get install zlib1g-devmake阶段
$ make
Command 'make' not found, but can be installed with:
apt install make
apt install make-guile
Ask your administrator to install one of them.缺少make,没有安装,进行安装即可
sudo apt install make二.使用外部模块编译Nginx
和上述不使用外部模块编译Nginx操作步骤类似
比如添加以下模块:
该模块为 CONNECT 方法请求提供支持。该方法主要用于通过代理服务器传输 SSL 请求。
ngx_http_upstream_check_module
支持上游健康检查
Nginx虚拟主机流量状态模块
为 Nginx 添加直接处理 文件上传 请求功能的第三方模块。它可以将上传的文件直接保存到磁盘上,并将元信息(如字段、文件名等)传给后端。
1.下载模块
# ngx_http_proxy_connect_module
wget https://github.com/chobits/ngx_http_proxy_connect_module/archive/refs/tags/v0.0.7.tar.gz
# ngx_http_upstream_check_module
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/tags/v0.4.0.tar.gz
# nginx-module-vts
wget https://github.com/vozlt/nginx-module-vts/archive/refs/tags/v0.2.4.tar.gz
# nginx-upload-module
wget https://github.com/fdintino/nginx-upload-module/archive/refs/tags/2.3.0.tar.gz解压,并创建软链
tar -xzvf 2.3.0.tar.gz
tar -xzvf v0.0.7.tar.gz
tar -xzvf v0.2.4.tar.gz
tar -xzvf v0.4.0.tar.gz
# 创建软链接
ln -s ../ngx_http_proxy_connect_module-0.0.7 modules/ngx_http_proxy_connect_module
ln -s ../nginx_upstream_check_module-0.4.0 modules/nginx_upstream_check_module
ln -s ../nginx-module-vts-0.2.4 modules/nginx-module-vts
ln -s ../nginx-upload-module-2.3.0 modules/nginx-upload-module
# check
$ ls -alh modules/* -d
lrwxrwxrwx 1 swift swift 40 Apr 18 03:57 modules/nginx-module-vts -> ../nginx-module-vts-0.2.4
lrwxrwxrwx 1 swift swift 28 Apr 18 03:57 modules/nginx-upload-module -> ../nginx-upload-module-2.3.0
lrwxrwxrwx 1 swift swift 51 Apr 18 03:52 modules/nginx_upstream_check_module -> ../nginx_upstream_check_module-0.4.0
lrwxrwxrwx 1 swift swift 53 Apr 18 03:51 modules/ngx_http_proxy_connect_module -> ../ngx_http_proxy_connect_module-0.0.7目录结构 tree -d -L 2 ./
./
├── modules
│ ├── nginx-module-vts -> ../nginx-module-vts-0.2.4
│ ├── nginx-upload-module -> ../nginx-upload-module-2.3.0
│ ├── nginx_upstream_check_module -> ../nginx_upstream_check_module-0.4.0
│ └── ngx_http_proxy_connect_module -> ../ngx_http_proxy_connect_module-0.0.7
├── nginx-1.27.5
│ ├── auto
│ ├── conf
│ ├── contrib
│ ├── html
│ ├── man
│ ├── objs
│ └── src
├── nginx-module-vts-0.2.4
│ ├── share
│ ├── src
│ ├── t
│ └── util
├── nginx-upload-module-2.3.0
│ └── t
├── nginx_upstream_check_module-0.4.0
│ ├── doc
│ ├── nginx-tests
│ ├── test
│ └── util
└── ngx_http_proxy_connect_module-0.0.7需要注意的是,有些第三方模块,需要打补丁,才能正常make编译通过
创建一个新的源码目录,避免干扰
rm -rf nginx-1.27.5
tar -xzvf nginx-1.27.5.tar.gz
cd nginx-1.27.52.打补丁
ngx_http_proxy_connect_module
参考: https://github.com/chobits/ngx_http_proxy_connect_module?tab=readme-ov-file#select-patch
不打补丁,编译会失败
cd nginx-1.27.5
patch -p1 < ../modules/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch日志
$ patch -p1 < ../modules/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
patching file src/http/ngx_http_core_module.c
Hunk #1 succeeded at 964 (offset 7 lines).
patching file src/http/ngx_http_parse.c
patching file src/http/ngx_http_request.c
Hunk #1 succeeded at 1157 (offset 55 lines).
Hunk #2 succeeded at 1810 with fuzz 1 (offset 64 lines).
Hunk #3 succeeded at 2117 (offset 44 lines).
patching file src/http/ngx_http_request.h
Hunk #1 succeeded at 419 (offset 5 lines).
patching file src/http/ngx_http_variables.cnginx_upstream_check_module
需要添加补丁,后续的配置才能生效。不添加补丁,编译通过,后面配置会不生效。
$ patch -p1 < ../modules/nginx_upstream_check_module/check_1.20.1+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
Hunk #2 succeeded at 253 (offset 12 lines).
Hunk #3 succeeded at 639 (offset 68 lines).
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
Hunk #2 succeeded at 219 (offset 8 lines).
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
Hunk #2 succeeded at 156 (offset 6 lines).
Hunk #3 succeeded at 221 (offset 6 lines).
patching file src/http/ngx_http_upstream_round_robin.c
Hunk #2 succeeded at 214 (offset 107 lines).
Hunk #3 succeeded at 349 (offset 163 lines).
Hunk #4 succeeded at 426 (offset 163 lines).
Hunk #5 succeeded at 554 (offset 171 lines).
Hunk #6 succeeded at 591 (offset 171 lines).
Hunk #7 succeeded at 665 with fuzz 2 (offset 177 lines).
Hunk #8 succeeded at 770 (offset 182 lines).
patching file src/http/ngx_http_upstream_round_robin.h
Hunk #1 succeeded at 55 (offset 17 lines).3.使用configure命令配置构建
在使用configure命令配置构建的过程中,调整命令,通过 --add-module= 启用外部模块
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
--with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
--add-module=../modules/nginx-module-vts \
--add-module=../modules/nginx-upload-module \
--add-module=../modules/nginx_upstream_check_module \
--add-module=../modules/ngx_http_proxy_connect_module通过
checking for getaddrinfo() ... found
configuring additional modules
adding module in ../modules/nginx-module-vts
+ ngx_http_vhost_traffic_status_module was configured
adding module in ../modules/nginx-upload-module
+ ngx_http_upload_module was configured
adding module in ../modules/nginx_upstream_check_module
checking for ngx_http_upstream_check_module ... found
+ ngx_http_upstream_check_module was configured
adding module in ../modules/ngx_http_proxy_connect_module
+ ngx_http_proxy_connect_module was configured
checking for PCRE2 library ... not found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using threads
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"4.编译
# 仅执行make,生成nginx可执行文件
make通过
objs/addon/src/ngx_http_vhost_traffic_status_node.o \
objs/addon/src/ngx_http_vhost_traffic_status_filter.o \
objs/addon/src/ngx_http_vhost_traffic_status_control.o \
objs/addon/src/ngx_http_vhost_traffic_status_limit.o \
objs/addon/src/ngx_http_vhost_traffic_status_display.o \
objs/addon/src/ngx_http_vhost_traffic_status_display_json.o \
objs/addon/src/ngx_http_vhost_traffic_status_display_prometheus.o \
objs/addon/src/ngx_http_vhost_traffic_status_set.o \
objs/addon/src/ngx_http_vhost_traffic_status_dump.o \
objs/addon/nginx-upload-module/ngx_http_upload_module.o \
objs/addon/nginx_upstream_check_module/ngx_http_upstream_check_module.o \
objs/addon/ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.o \
objs/ngx_modules.o \
-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie -ldl -lpthread -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/etc/nginx|" \
-e "s|%%PID_PATH%%|/var/run/nginx.pid|" \
-e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \
-e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/home/swift/nginx/nginx-1.27.5'验证
可执行文件 objs/nginx
版本详情
$ ./objs/nginx -V
nginx version: nginx/1.27.5
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' --add-module=../modules/nginx-module-vts --add-module=../modules/nginx-upload-module --add-module=../modules/nginx_upstream_check_module --add-module=../modules/ngx_http_proxy_connect_module问题记录
ngx_http_proxy_connect_module模块编译失败
之前遇到的问题,在这里贴出来
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c: In function 'ngx_http_proxy_connect_handler':
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c:1459:22: error: 'NGX_HTTP_CONNECT' undeclared (first use in this function)
if (r->method != NGX_HTTP_CONNECT || !plcf->accept_connect) {
^
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c:1459:22: note: each undeclared identifier is reported only once for each function it appears in
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c:1487:28: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'connect_host'
url.url.len = r->connect_host.len;
^
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c:1488:29: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'connect_host'
url.url.data = r->connect_host.data;
^
../ngx_http_proxy_connect_module/ngx_http_proxy_connect_module.c:1492:24: error: 'ngx_http_request_t {aka struct ngx_http_request_s}' has no member named 'connect_host'
url.url.len = r->connect_host.len;
解决:
经过查找问题,发现ngx_http_proxy_connect_module该模块构建nginx的时候,需要打补丁。打完补丁后,make通过。
ngx_http_proxy_connect_module打补丁patch
swift@l-k8s-node-002:~/nginx$ cd nginx-1.20.1/
swift@l-k8s-node-002:~/nginx/nginx-1.20.1$ patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
patching file src/http/ngx_http_core_module.c
Hunk #1 succeeded at 957 (offset 7 lines).
patching file src/http/ngx_http_parse.c
patching file src/http/ngx_http_request.c
Hunk #1 succeeded at 1116 (offset 24 lines).
Hunk #2 succeeded at 1752 (offset 34 lines).
patching file src/http/ngx_http_request.h
patching file src/http/ngx_http_variables.c
Hunk #1 succeeded at 163 (offset 2 lines).