Nginx支持TLS1.3部署详解


早就听说有TLS1.3了,一直心痒痒,想折腾折腾试试。以前浏览器支持的不多,网上也没太多人试过,不太敢趟雷。现在有一些大型网站网站已经弄上了TLS1.3,也有不少博主给自己的博客升级了TLS1.3了,留下了宝贵的经验。我也忍不住了,今天就来折腾一下看看。Openssl 1.1.1 LTS已经发布,更新一下TLS1.3正式版。
 
软件版本
◦Nginx: nginx-1.15.4
◦OpenSSL: openssl-1.1.1(LTS)

教程

安装依赖

sudo apt update
sudo apt install -y build-essential libpcre3 libpcre3-dev zlib1g-dev liblua5.1-dev libluajit-5.1-dev libgeoip-dev google-perftools libgoogle-perftools-dev

下载并解压所需软件

wget https://nginx.org/download/nginx-1.15.4.tar.gz
tar zxf nginx-1.15.4.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz
tar zxf openssl-1.1.1.tar.gz

OpenSSL打补丁

pushd openssl-1.1.1
#打TLS1.3 Draft 23, 26, 28, Final补丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/openssl-equal-1.1.1_ciphers.patch | patch -p1
#打ignore Strict-SNI log补丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/openssl-ignore_log_strict-sni.patch | patch -p1
popd

Nginx补丁

pushd nginx-1.15.4
#打SPDY, HTTP2 HPACK, Dynamic TLS Record, Fix Http2 Push Error, PRIORITIZE_CHACHA补丁
curl https://raw.githubusercontent.com/kn007/patch/43f2d869b209756b442cfbfa861d653d993f16fe/nginx.patch | patch -p1
curl https://raw.githubusercontent.com/kn007/patch/c59592bc1269ba666b3bb471243c5212b50fd608/nginx_auto_using_PRIORITIZE_CHACHA.patch | patch -p1
#打Strict-SNI补丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/nginx_strict-sni.patch | patch -p1
popd

编译安装Nginx

如果原本编译安装过Nginx,可以输入nginx -V,查看以前的configure配置。在后面加上所需参数进行编译。

关键参数:
◦添加--with-openssl=../openssl-1.1.1来指定OpenSSL路径
◦HTTP2 HPACK需要加入--with-http_v2_hpack_enc参数。
◦SPDY需要加入--with-http_spdy_module

注意将--with-openssl参数改为自己的OpenSSL文件夹地址。

我的完整configure命令如下,请类比进行。

cd nginx-1.15.4

./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-threads \
--with-file-aio \
--with-pcre-jit \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_realip_module \
--with-http_addition_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-stream_realip_module \
--with-http_slice_module \
--with-http_geoip_module \
--with-google_perftools_module \
--with-openssl=../openssl-1.1.1 \
--with-http_v2_hpack_enc \
--with-http_spdy_module

configure完成后,输入以下语句开始编译。

make

编译完成后,如果没有报错,输入以下内容进行安装。

make install

配置Nginx虚拟主机

将以下内容加入你的conf文件的相应位置,替换掉原本的相应内容。由于安全性升级的考虑,我删除了TLS1和TLS1.1。除此以外,TLS1.3的新加密套件只能在TLS1.3中使用,旧的加密套件不能用于TLS1.3。似乎所有虚拟主机都要配置才能使用TLS1.3。

ssl_early_data on;
ssl_protocols 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;
ssl_prefer_server_ciphers on;

最后使用nginx -t测试nginx配置的正确性。

成功

重启Nginx,你会发现你的网站已经是TLS1.3连接了。

Nginx支持TLS1.3部署详解Nginx支持TLS1.3部署详解

 

一点问题

我原本使用的是Nginx 1.14.0,现在升级到了1.15.4,配置文件可能会报以下警告。当然,由于只是警告,并不会影响运行,只是我强迫症受不了。

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /usr/local/nginx/conf/vhost/www.iszy.me.conf:22

这是由于在主线版本v1.15.0以后,弃用了ssl标识。官方原话是这样的:

The “ssl” directive is deprecated; the “ssl” parameter of the “listen” directive should be used instead.

解决方案很简单,只需要删除配置文件中的ssl on语句,采用listen语句替代,如listen 443 ssl。原本就使用listen 443 ssl语句的就更简单了,直接删除ssl on语句即可。

后话

好了,到这里,教程算是结束了。OpenSSL 1.1.1 LTS已经正式发布了,TLS1.3也已经正式公布。现阶段,Nginx、Apache等主流web服务器还没有官方支持,还需要通过打补丁的方式进行支持。期待TLS1.3全面铺开后对网络隐私和抗审查作出的贡献。

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2018-11/155252.htm

相关内容

    暂无相关文章