升级nginx,编译make的时候报undefined reference to `SSL_CTX_set_alpn_select_cb'

编译安装nginx的时候

./configure --with-http_ssl_module

报了如下错误

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_get_ciphers':

/root/nginx-1.12.0/src/event/ngx_event_openssl.c:3358: undefined reference to `SSL_CIPHER_find'

/root/nginx-1.12.0/src/event/ngx_event_openssl.c:3378: undefined reference to `SSL_CIPHER_find'

objs/src/event/ngx_event_openssl.o: In function `ngx_ssl_check_host':

/root/nginx-1.12.0/src/event/ngx_event_openssl.c:3169: undefined reference to `X509_check_host'

objs/src/http/ngx_http_request.o: In function `ngx_http_ssl_handshake_handler':

/root/nginx-1.12.0/src/http/ngx_http_request.c:784: undefined reference to `SSL_get0_alpn_selected'

objs/src/http/modules/ngx_http_ssl_module.o: In function `ngx_http_ssl_merge_srv_conf':

/root/nginx-1.12.0/src/http/modules/ngx_http_ssl_module.c:690: undefined reference to `SSL_CTX_set_alpn_select_cb'

collect2: ld returned 1 exit status

原因是升级openssl编译导致。
查看openssl的版本信息,及安装目录

[root@ibopo-web local]# openssl version -a
OpenSSL 1.0.2r  26 Feb 2019
built on: reproducible build, date unspecified
platform: linux-x86_64
options:  bn(64,64) rc4(8x,char) des(idx,cisc,16,int) idea(int) blowfish(idx) 
compiler: gcc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DRC4_ASM -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
OPENSSLDIR: "/usr/local/ssl"

解决步骤:
打开nginx源文件下的/usr/local/src/nginx-1.9.9/auto/lib/openssl/conf文件:
找到这么一段代码:

 CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
 CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
 CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

修改成以下代码:

 CORE_INCS="$CORE_INCS $OPENSSL/include"
 CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
 CORE_LIBS="$CORE_LIBS $NGX_LIBDL"

然后再进行Nginx的编译安装即可
在configure之前,我加入了如下两句:

export PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/ssl/lib

编译的时候,带上openssl,编译通过

./configure --with-http_ssl_module  --with-openssl=/usr/local/ssl

参考 http://blog.chinaunix.net/uid-2274226-id-5756596.html

猜你喜欢

转载自blog.csdn.net/huangbaokang/article/details/89847725