编译Windows平台的Nginx+ngx_http_proxy_connect_module

编译Windows平台的Nginx+ngx_http_proxy_connect_module

背景:由于公司的正向出局代理是windows机器。机器上的Squid不稳定,打算替换成nginx+ngx_http_proxy_connect_module实现。通过几天痛苦的尝试,最后参考了github大神项目通过在线CICD工具编译window平台可用的ng。

步骤:

获取git可识别的patch

由于CI平台没有patch命令,先在本地准备git可以识别的patch格式。没有直接转换,因为不发现不行。

获取ngx_http_proxy_connect_module里面的patch,执行后再传到仓库里面,待CI里面使用git am -3 ../nginx-*.patch给源码打补丁

git add .
git commit -m 'patch proxy_connect_rewrite_102101.patch'
git format-patch -1 HEAD 
// 获取git0001-patch-proxy_connect_rewrite_102101.patch.patch 拷贝到项目目录备用

build.sh 修改

修改nginx-build-msys2\nginx-build-msys2.sh参数

  • patch 源码git am -3 ../nginx-*.patch

  • 添加configure_args

    configure_args+=(
        --add-module=../ngx_http_proxy_connect_module
    )
    
  • 删除不需要的debug包 加快编译速度

关联appveyor CI工具

https://www.appveyor.com

在这里面把自己的git仓库添加进去,就可以跑了

项目仓库

成品包
可以在Releases里面下载编译好的包

  • nginx-*-i686-_http_proxy_connect_module: 32-bit nginx
  • nginx-*-x86_64-_http_proxy_connect_module: 32-bit nginx

测试

通过-V 可以看到已经编译成功,并且可以正常使用

C:\Users\Administrator\Downloads\nginx-bin>nginx-1.25.4-x86_64-ngx_http_proxy_connect_module.exe -t
nginx: the configuration file C:\Users\Administrator\Downloads\nginx-bin/conf/nginx.conf syntax is ok
nginx: configuration file C:\Users\Administrator\Downloads\nginx-bin/conf/nginx.conf test is successful

C:\Users\Administrator\Downloads\nginx-bin>nginx-1.25.4-x86_64-ngx_http_proxy_connect_module.exe -s reload
nginx: [error] invalid PID number "" in "C:\Users\Administrator\Downloads\nginx-bin/logs/nginx.pid"

C:\Users\Administrator\Downloads\nginx-bin>nginx-1.25.4-x86_64-ngx_http_proxy_connect_module.exe -s reload

C:\Users\Administrator\Downloads\nginx-bin>nginx-1.25.4-x86_64-ngx_http_proxy_connect_module.exe -V
nginx version: nginx/1.25.4
built by gcc 13.2.0 (Rev2, Built by MSYS2 project)
built with OpenSSL 1.1.1w  11 Sep 2023
TLS SNI support enabled
configure arguments: --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body --http-proxy-temp-path=temp/proxy --http-fastcgi-temp-path=temp/fastcgi --http-scgi-temp-path=temp/scgi --http-uwsgi-temp-path=temp/uwsgi --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-pcre=pcre2-10.42 --with-pcre-jit --with-zlib=zlib-1.3 --with-ld-opt=-Wl,--gc-sections,--build-id=none --prefix= --with-http_v2_module --with-openssl=openssl-1.1.1w --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_module --add-module=../ngx_http_proxy_connect_module --with-cc-opt='-DFD_SETSIZE=1024 -s -O2 -fno-strict-aliasing -pipe' --with-openssl-opt='no-tests -D_WIN32_WINNT=0x0501'

总结

要学会使用CICD工具解决编译问题。

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值