解决编译安装 nginx时遇到的报错
下载解压切换目录略~
编译nginx
[ nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8
没有报错
然后我们make
[ nginx-1.10.1]# 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=]
h ^= data[2] << 16;^~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;^~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
case 1:
^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:473: objs/src/core/ngx_murmurhash.o] Error 1
make[1]: Leaving directory ‘/root/nginx-1.10.1‘
make: *** [Makefile:8: build] Error 2
分析原因:
是将警告当成了错误处理,打开 nginx的安装目录/objs/Makefile,去掉CFLAGS中的-Werror,再重新make
-Wall 表示打开gcc的所有警告
-Werror,它要求gcc将所有的警告当成错误进行处理
好的,第一个问题解决了,然后make又出现一个错误
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’
cd.current_salt[0] = ~salt[0];
^
make[1]: *** [objs/Makefile:774: objs/src/os/unix/ngx_user.o] Error 1
make[1]: Leaving directory ‘/root/nginx-1.10.1‘
make: *** [Makefile:8: build] Error 2
这里提示我们struct crypt_data’没有名为‘current_salt’的成员:cd.current_salt[0] = ~salt[0];
最好的办法是换一个版本,因为条件限制,我们就进到源码里把这行直接注释掉好了。
[ nginx-1.10.1]# vim src/os/unix/ngx_user.c
进去找到第36行
第三个错误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
原因:由于默认使用了openssl 1.1.x 版本,导致的API不一致引起
解决:
直接安装openssl1.0版本
wget http://www.openssl.org/source/openssl-1.1.0e.tar.gz
//下载openssl[ ~]# 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 下[ openssl-1.1.0e]# ./config -t
[ openssl-1.1.0e]# make depend
//一种度makefile的规则,通过扫描仪个目录下的所有C\C++ 代码,从而判专断出文件之间的依赖关系,如a.cc文件中调用了b.h(如以形势include<b.h>),如果之后a.cc文件被改动,那 么只需要重新编属译a.cc文件,不需要编译b.h文件。否则所有的文件都需要重新编译。[ openssl-1.1.0e]# cd /usr/local
[ local]# ln -s openssl ssl
[ local]# echo "/usr/local/openssl/lib" >>/etc/ld.so.conf
[ local]# cd -
/root/openssl-1.1.0e[ openssl-1.1.0e]# ldconfig
[ openssl-1.1.0e]# echo $?
0[ openssl-1.1.0e]# echo "PATH=$PATH:/usr/local/openssl/bin" >> /etc/profile && source /etc/profile
好嘞,查看版本 ,OK
我们再次进入nginx下
[ nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8 --with-openssl=../opensll-1.1.0e
!注意这里还是要把objs/Makefile下的werror去掉
然后启动一下nginx
[ nginx-1.10.1]# /usr/local/nginx/sbin/nginx
设置一下环境变量
[ sbin]# echo "PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile && source /etc/profile
查看一下进程和端口是否开启
看看chrome能不能打开nginx的网页
[ ~]# echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf &" >>/etc/rc.local
(/etc/rc.local 这个文件是系统启动后会自动执行的,我们就将启动命令加入到这个文件中)
如果你发现你的进程没有成功的启动可能是因为你的这个脚本文件没有可以执行的权限 请给该文件增加 其他人可以执行的权限 chmod o+x /etc/rc.local后重启再次查看