配置
os: centos 7
nginx-version: 1.9.9
libs: gcc gcc-g++
pcre pcre-devel
zlib zlib-devel
openssl openssl-devel
问题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=]
37 | h ^= data[2] << 16;
| ~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
38 | case 2:
| ^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
39 | h ^= data[1] << 8;
| ~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
40 | case 1:
| ^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:445: objs/src/core/ngx_murmurhash.o] Error 1
make[1]: Leaving directory '/home/xing/application/nginx-1.9.9'
make: *** [Makefile:8: build] Error 2
该问题是因为设定的编译警告,讲编译警告作为错误输出,并终止编译
解决方案
进入 nginx/jobs/Makefile 找到CFLAGS并删除其中的-Werror
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused -Werror -g
问题2
src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
src/os/unix/ngx_user.c:36:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
36 | cd.current_salt[0] = ~salt[0];
| ^
make[1]: *** [objs/Makefile:732: objs/src/os/unix/ngx_user.o] Error 1
make[1]: Leaving directory '/home/xing/application/nginx-1.9.9'
make: *** [Makefile:8: build] Error 2
该问题是因为glibc引起的错误,我们需要进入 objs/src/os/unix/ngx_user.c找到并删除 cd.current_salt[0] = ~salt[0];
#ifdef __GLIBC__
/* work around the glibc bug */
cd.current_salt[0] = ~salt[0];
#endif
后记
官方于1.14.2版本中删除了这个由glibc引起的错误
总结
nginx尽量使用较新版本,能使用稳定版就使用稳定版,这样可以避免很多麻烦和问题。