freebsd 与 nginx 与 openssl编译 http2

来源:互联网 发布:图像清晰度检测算法 编辑:程序博客网 时间:2024/05/21 22:35

nginx1.9之后才支持http2 必须使用openssl1.0.2版本

使用版本:

平台:freebsd10.3

nginx版本:nginx1.10.2

openssl版本:openssl1.0.2h

编译器:freebsd自带cc


./configure --prefix=/root/nginx2 --with-openssl=/root/openssl-OpenSSL_1_0_2h --with-openssl-opt=cc  --with-http_ssl_module --with-http_v2_module --with-debug --with-cc-opt=-std=c11


--prefix 指定生成目录

--with-openssl openssl源码路径

--with-openssl-opt 设置openssl编译选项,设置为cc表示使用cc编译器,默认gcc,实际没什么用,见后面

--with-http_ssl_module ssl模块开启

--with-http_v2_module 需要支持http2

 --with-debug 编译debug版本,错误日志加上debug时会显示详细流程

--with-cc-opt=-std  c编译选项,有些模块是c++11编写的时候 c11


make

出现

openssl编译错误

1、没有设置选项--with-openssl-opt=cc

Configured for BSD-x86-elf.


*** Because of configuration changes, you MUST do the following before
*** building:


        make depend
making all in crypto...
/usr/local/bin/perl5 ../util/mkbuildinf.pl "gcc -I. -I.. -I../include  -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -fomit-frame-pointer -Wall -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DGHASH_ASM" "BSD-x86-elf" >buildinf.h
gcc -I. -I.. -I../include  -DOPENSSL_THREADS -pthread -D_THREAD_SAFE -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -DL_ENDIAN -O3 -fomit-frame-pointer -Wall -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DGHASH_ASM -c cryptlib.c -o cryptlib.o
make[3]: exec(gcc) failed (No such file or directory)
*** Error code 1


Stop.
make[3]: stopped in /root/openssl-OpenSSL_1_0_2h/crypto
*** Error code 1


Stop.
make[2]: stopped in /root/openssl-OpenSSL_1_0_2h

原因是openssl会默认使用gcc编译器,没有gcc编译器时出错

解决方法:安装gcc


2、设置了选项--with-openssl-opt=cc

Operating system: i386-pc-freebsd10.3
Configuring for BSD-x86-elf
target already defined - BSD-x86-elf (offending arg: cc)
*** Error code 255


Stop.
make[1]: stopped in /root/nginx-1.10.2
*** Error code 1


Stop.
make: stopped in /root/nginx-1.10.2


原因是使用./config来设置openssl,应该要用./Configure才会设置环境之类的

解决方法:

./configure之后会生成一个Makefile文件

修改objs/Makefile

&& ./config --prefix=/root/openssl-OpenSSL_1_0_2h/.openssl no-shared cc 

改为

&&./Configure cc --prefix=/root/openssl-OpenSSL_1_0_2h/.openssl no-shared (第二项必须为编译器)


然后重新

make

make install

到对应的生成路径下,修改

conf/nginx.conf

 

server {
        listen       443 ssl http2;
        server_name  localhost;


        #charset koi8-r;
        ssl_certificate /root/nginx2/ssl/server.crt;  #证书配置 ,
        ssl_certificate_key /root/nginx2/ssl/server.key; #


生成证书见:

http://www.cnblogs.com/bugutian/p/6628455.html


保存之后执行

到sbin目录下

./nginx -c conf/nginx.conf


重启为:

./nginx -c conf/nginx.conf -s reload

停止为:

./nginx -c conf/nginx.conf -s stop -->必须使用这个方式停止,kill方法不完全



原创粉丝点击