Home > 系统管理 > Nginx替换OpenSSL为LibreSSL

Nginx替换OpenSSL为LibreSSL

先科普
LibreSSL是OpenSSL加密软件库的一个分支,为一个安全套接层(SSL)和传输层安全(TLS)协议的开源实现。在OpenSSL爆出心脏出血安全漏洞之后,一些OpenBSD开发者于2014年4月创立了LibreSSL,目标是重构OpenSSL的代码,以提供一个更安全的替代品。LibreSSL复刻自OpenSSL库的1.0.1g分支,它将遵循其他OpenBSD项目所使用的安全指导原则。

简单总结一下LibreSSL的优缺点
优点:兼容OpenSSL,代码简单,分支清晰,便于安装、使用和维护
缺点:不支持旧安全算法,部分加密算法效率不高。

安装编译环境

#安装编译环境
yum install -y gcc gcc-c++ pcre-devel openssl openssl-devel

创建工作目录,统一使用绝对路径

#创建工作目录,统一使用绝对路径
mkdir /work
cd /work

下载LibreSSL源代码

cd /work
wget http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.4.2.tar.gz
tar xvzf libressl-2.4.2.tar.gz

下载nginx源代码

cd /work
wget http://nginx.org/download/nginx-1.10.1.tar.gz
tar -xzvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

配置编译选项,将openssl替换为libressl “–with-openssl=/work/libressl-2.4.2”

./configure --with-openssl=/work/libressl-2.4.2/ \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module

编译和安装Nginx + Libressl

#编译和安装
make;make install
#创建链接
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
ln -s /usr/local/nginx/conf /etc/nginx

测试编译和安装Nginx + Libressl结果

#测试
nginx -V

输出结果

nginx version: nginx/1.10.1 (Ubuntu)
built by gcc 4.9.2 20150212 (Red Hat 4.9.2-6)
built with LibreSSL 2.4.2
TLS SNI support enabled

完整的编译和安装Nginx + Libressl脚本

#安装编译环境
yum install -y gcc gcc-c++ pcre-devel openssl openssl-devel
#创建工作目录,统一使用绝对路径
mkdir /work;cd /work
 
#下载LibreSSL源代码
wget http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.4.2.tar.gz
tar xvzf libressl-2.4.2.tar.gz
 
#下载nginx源代码
cd /work
wget http://nginx.org/download/nginx-1.10.1.tar.gz
tar -xzvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
 
#配置编译选项,
./configure --with-openssl=/work/libressl-2.4.2/ \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module
 
#编译和安装
make;make install
#创建链接
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
ln -s /usr/local/nginx/conf /etc/nginx
 
#测试
nginx -V

参考
http://www.oschina.net/translate/nginx-libressl-first-test?cmp
https://community.centminmod.com/threads/libressl-2-4-2-released.8195/

Categories: 系统管理 Tags: , , ,
You must be logged in to post a comment.