nginx 编译安装sticky时报错处理

一般企事业单位的内网按照部门划分网段,ip hash 的负载均衡策略容易导致负载失衡,比如某个网段地址多,一些网段地址少,IP hash是基于IPv4地址的前三段来区分的(开发者可能觉得机器处理区分所有IP太累么?配置文件中让用户自己选择不好么?)。所以要使用sticy 模块来解决这个问题。不过使用nginx 1.25 和1.24等较新版本编译sticky模块时,make阶段报错:

  -o objs/addon/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.o \
        /opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c
/opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c: 在函数‘ngx_http_init_sticky_peer’中:
/opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:47: 错误:传递‘ngx_http_parse_multi_header_lines’的第 1 个参数时在不兼容的指针类型间转换 [-Werror=incompatible-pointer-types]
  207 |         if (ngx_http_parse_multi_header_lines(&r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
      |                                               ^~~~~~~~~~~~~~~~~~~~~
      |                                               |
      |                                               ngx_table_elt_t ** {或称 struct ngx_table_elt_s **}
In file included from /opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:9:
src/http/ngx_http.h:106:72: 附注:需要类型‘ngx_http_request_t *’ {或称 ‘struct ngx_http_request_s *’},但实参的类型为‘ngx_table_elt_t **’ {或称 ‘struct ngx_table_elt_s **’}
  106 | _table_elt_t *ngx_http_parse_multi_header_lines(ngx_http_request_t *r,
      |                                                 ~~~~~~~~~~~~~~~~~~~~^

/opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:70: 错误:传递‘ngx_http_parse_multi_header_lines’的第 2 个参数时在不兼容的指针类型间转换 [-Werror=incompatible-pointer-types]
  207 |  (ngx_http_parse_multi_header_lines(&r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
      |                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                            |
      |                                                            ngx_str_t *

In file included from /opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:9:
src/http/ngx_http.h:107:22: 附注:需要类型‘ngx_table_elt_t *’ {或称 ‘struct ngx_table_elt_s *’},但实参的类型为‘ngx_str_t *’
  107 |     ngx_table_elt_t *headers, ngx_str_t *name, ngx_str_t *value);
      |     ~~~~~~~~~~~~~~~~~^~~~~~~
/opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:207:13: 错误:提供给函数‘ngx_http_parse_multi_header_lines’的实参太少
  207 |         if (ngx_http_parse_multi_header_lines(&r->headers_in.cookie, &iphp->sticky_conf->cookie_name, &route) != NGX_DECLINED) {
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.c:9:
src/http/ngx_http.h:106:18: 附注:在此声明
  106 | ngx_table_elt_t *ngx_http_parse_multi_header_lines(ngx_http_request_t *r,
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1:所有的警告都被当作是错误
make[1]: *** [objs/Makefile:1594:objs/addon/nginx-goodies-nginx-sticky-module-ng-08a395c66e42/ngx_http_sticky_module.o] 错误 1
make[1]: 离开目录“/opt/nginx-1.24.0”
make: *** [Makefile:10:build] 错误 2
[root@localhost nginx-1.24.0]# ^C
[root@localhost nginx-1.24.0]# ^C

搞了半天,从网上也搜了不少文章介绍的方法都不行。 直到看到了这个文章:

nginx1.24版本编译sticky模块报‘ngx_http_headers_in_t’ has no member named ‘cookies’的解决方案_error: ‘ngx_http_headers_in_t’ has no member named-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_21076567/article/details/134922929主要两句话:

替换 sticky模块下ngx_http_sticky_module.c文件的文件内容:

 sed -i "s/ngx_http_parse_multi_header_lines.*/ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, \&iphp->sticky_conf->cookie_name, \&route) != NULL){/g" ngx_http_sticky_module.c

实测1.24 和1.25的源码编译均有效。看起来好的解决办法就是简单粗暴。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值