编译nginx时openssl报错的解决方案

编译nginx时提示openssl版本错误

 src/event/ngx_event_openssl.c: In function ‘ngx_ssl_dhparam’:
src/event/ngx_event_openssl.c:954:11: error: dereferencing pointer to incomplete type ‘DH’ {aka ‘struct dh_st’}
         dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
           ^~
src/event/ngx_event_openssl.c: In function ‘ngx_ssl_connection_error’:
src/event/ngx_event_openssl.c:1941:21: error: ‘SSL_R_NO_CIPHERS_PASSED’ undeclared (first use in this function); did you mean ‘SSL_R_NO_CIPHERS_SPECIFIED’?
             || n == SSL_R_NO_CIPHERS_PASSED                          /*  182 */
                     ^~~~~~~~~~~~~~~~~~~~~~~
                     SSL_R_NO_CIPHERS_SPECIFIED
src/event/ngx_event_openssl.c:1941:21: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [objs/Makefile:816: objs/src/event/ngx_event_openssl.o] Error 1
make[1]: Leaving directory '/root/nginx-1.10.1'
make: *** [Makefile:8: build] Error 2

分析原因:

由于使用yum默认使用了openssl 1.1.x 版本,导致的API不一致引起的

解决办法:

直接编译安装openssl1.0版本

wget  http://www.openssl.org/source/openssl-1.1.0e.tar.gz
tar -zxvf   openssl-1.1.0e.tar.gz
cd openssl-1.1.0e/ &&./config shared zlib  --prefix=/usr/local/openssl && make && make install  #进入目录把openssl编译安装到 /usr/local/openssl 下
./config -t
make depend  //是一种makefile的规则,通过扫描仪个目录下的所有CC++ 代码,从而判断出文件之间的依赖关系,如a.cc文件中调用了b.h(如以形势include<b.h>),如果之后a.cc文件被改动,那么只需要重新编译a.cc文件,不需要编译b.h文件。否则所有的文件都需要重新编译。
cd /usr/local
ln -s openssl ssl
echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
ldconfig
echo "PATH=$PATH:/usr/local/openssl/bin" >> /etc/profile && source /etc/profile      #添加环境变量

好嘞,查看openssl版本 ,OK

我们再次进入nginx下

./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../opensll-1.1.0e  
make && make install      #编译安装
/usr/local/nginx/sbin/nginx       #启动nginx

查看一下进程和端口是否开启

查看浏览器能不能正常打开nginx的网页

原文地址:https://www.cnblogs.com/hxlinux/p/12900495.html