搜索
您的当前位置:首页正文

nginx源码编译时常见错误解决方法

来源:好走旅游网
nginx源码编译时常见错误解决⽅法

最近在研究nginx源码,准备对源码进⾏调试,需要'-g'选项编译nginx,便于使⽤GDB调试nginx。编译源码的过程中发现很多问题,决定进⾏⼀番梳理。编译环境:

###Ubuntu20.04&gcc--version 9.3.0###nginx源码版本:nginx-1.12.0编译nginx所需要的库及版本号:pcre-8.37openssl-1.1.0hzlib-1.2.11配置命令:

./configure --prefix=/home/zyz/nginx1.12.0/ --with-http_ssl_module --with-http_stub_status_module --with-pcre=/home/zyz/pcre-8.37/ --with-openssl=/home/zyz/openssl-1.1.0h/ --with-zlib=/home/zyz/zlib-1.2.11/编译命令:make报错:

make -f objs/Makefile

make[1]: Entering directory '/home/zyz/nginx-1.12.0'cd ../pcre-8.37/ \\

&& if [ -f Makefile ]; then make distclean; fi \\

&& CC=\"cc\" CFLAGS=\"-O2 -fomit-frame-pointer -pipe \" \\./configure --disable-shared /bin/sh -3: permission deny解决⽅法:

经过⼀番分析发现是pcre-8.37 和openssl-1.1.0h库中的configure⽂件和config⽂件默认⽆执⾏权限,果断进⼊ 两个库⽂件夹,执⾏chmod 777 configure ; chmod 777 config于是乎make,开始⼤量编译...过了⼀会⼉,⼜报了另外⼀个错误!

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:482:objs/src/core/ngx_murmurhash.o] 错误 1make[1]: 离开⽬录“/home/zyz/nginx-1.12.0”make: *** [Makefile:8:build] 错误 2解决⽅法:

进⼊objs/Makefile,打开Makefile⽂件将编译选项中的CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -werror -g中的“-werror\"删除。

###-werror是将警告对待成错误(warning treated as error)。继续进⾏编译...⼜报错误了。。。如下:

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:797:objs/src/os/unix/ngx_user.o] 错误 1make[1]: 离开⽬录“/home/zyz/nginx-1.12.0/nginx-1.12.0”make: *** [Makefile:8:build] 错误 2解决⽅法:

经过百度发现需要进⼊../src/os/unix/ngx_user.c中进⾏源码修改。只需要注释第36⾏代码即可。/* cd.current_salt[0] = ~salt[0];*/继续进⾏编译...编译完成!

sed -e \"s|%%PREFIX%%|/home/zyz/nginx1.12.0/|\" \\

-e \"s|%%PID_PATH%%|/home/zyz/nginx1.12.0//logs/nginx.pid|\" \\ -e \"s|%%CONF_PATH%%|/home/zyz/nginx1.12.0//conf/nginx.conf|\" \\

-e \"s|%%ERROR_LOG_PATH%%|/home/zyz/nginx1.12.0//logs/error.log|\" \\ < man/nginx.8 > objs/nginx.8

make[1]: 离开⽬录“/home/zyz/nginx-1.12.0”安装make install

root@zyz:/home/zyz/nginx-1.12.0# make installmake -f objs/Makefile install

make[1]: 进⼊⽬录“/home/zyz/nginx-1.12.0”

test -d '/home/zyz/nginx1.12.0/' || mkdir -p '/home/zyz/nginx1.12.0/'test -d '/home/zyz/nginx1.12.0//sbin' \\

|| mkdir -p '/home/zyz/nginx1.12.0//sbin'test ! -f '/home/zyz/nginx1.12.0//sbin/nginx' \\ || mv '/home/zyz/nginx1.12.0//sbin/nginx' \\ '/home/zyz/nginx1.12.0//sbin/nginx.old'

cp objs/nginx '/home/zyz/nginx1.12.0//sbin/nginx'test -d '/home/zyz/nginx1.12.0//conf' \\

|| mkdir -p '/home/zyz/nginx1.12.0//conf'cp conf/koi-win '/home/zyz/nginx1.12.0//conf'cp conf/koi-utf '/home/zyz/nginx1.12.0//conf'cp conf/win-utf '/home/zyz/nginx1.12.0//conf'test -f '/home/zyz/nginx1.12.0//conf/mime.types' \\

|| cp conf/mime.types '/home/zyz/nginx1.12.0//conf'

cp conf/mime.types '/home/zyz/nginx1.12.0//conf/mime.types.default'test -f '/home/zyz/nginx1.12.0//conf/fastcgi_params' \\

|| cp conf/fastcgi_params '/home/zyz/nginx1.12.0//conf'cp conf/fastcgi_params \\

'/home/zyz/nginx1.12.0//conf/fastcgi_params.default'test -f '/home/zyz/nginx1.12.0//conf/fastcgi.conf' \\

|| cp conf/fastcgi.conf '/home/zyz/nginx1.12.0//conf'

cp conf/fastcgi.conf '/home/zyz/nginx1.12.0//conf/fastcgi.conf.default'test -f '/home/zyz/nginx1.12.0//conf/uwsgi_params' \\

|| cp conf/uwsgi_params '/home/zyz/nginx1.12.0//conf'cp conf/uwsgi_params \\

'/home/zyz/nginx1.12.0//conf/uwsgi_params.default'test -f '/home/zyz/nginx1.12.0//conf/scgi_params' \\

|| cp conf/scgi_params '/home/zyz/nginx1.12.0//conf'

cp conf/scgi_params \\

'/home/zyz/nginx1.12.0//conf/scgi_params.default'test -f '/home/zyz/nginx1.12.0//conf/nginx.conf' \\

|| cp conf/nginx.conf '/home/zyz/nginx1.12.0//conf/nginx.conf'cp conf/nginx.conf '/home/zyz/nginx1.12.0//conf/nginx.conf.default'test -d '/home/zyz/nginx1.12.0//logs' \\

|| mkdir -p '/home/zyz/nginx1.12.0//logs'test -d '/home/zyz/nginx1.12.0//logs' \\

|| mkdir -p '/home/zyz/nginx1.12.0//logs'test -d '/home/zyz/nginx1.12.0//html' \\ || cp -R html '/home/zyz/nginx1.12.0/'test -d '/home/zyz/nginx1.12.0//logs' \\

|| mkdir -p '/home/zyz/nginx1.12.0//logs'make[1]: 离开⽬录“/home/zyz/nginx-1.12.0”⽣成nginx可执⾏⽂件 执⾏./nginx

好了,nginx源码的编译及执⾏就介绍完了。下篇介绍nginx的调试,哈哈2020-11-28 11:27:33

因篇幅问题不能全部显示,请点此查看更多更全内容

Top