nginx的TLS版本设置(TLS1.1 TLSv1.2 TLSv1.3)
环境:linux/nginx
在一些使用环境中,早期的https版本由于安全性不够好已经不建议使用,托管商或代码会要求网站停止使用不安全的TLS1.0/TLS1.1协议。
对应于nginx中相关配置指令是ssl_protocols,修改后通过sslscan工具发现始终没生效。查阅nginx的文档,发现有这么一句话If the directive is specified on the [server] level, the value from the default server can be used。
翻译过来就是:如果在server块中使用ssl_protocols了,那么该指定会直接使用默认的值,而并不是当前server块中指定的值。而如果nginx没有默认的server时,将会使用第一个server作为默认的server。因此需要在第一个server或默认的server中,配置ssl_protocols。也可以在http块中指定ssl_protocols。
http {
#...
# 指定支持的 SSL/TLS 协议版本
ssl_protocols TLSv1.2 TLSv1.3;
#...
}
再翻译一下,一个linux服务器通常会在nginx中跑多个网站,以lnmp.sh为例,系统在安装时会在总配置文件nginx.conf中建一个默认站点,其它新建的站点每个网站会在vhost目录下生成一个单独的配置文件:
//以lnmp.sh为例,配置文件在/usr/local/nginx/nginx.conf中:
server
{
listen 800 default_server reuseport;
#listen [::]:80 default_server ipv6only=on;
server_name _; //默认站点
index index.html index.htm index.php;
root /home/wwwroot/default;
ssl_protocols TLSv1.2 TLSv1.3;
...
}
include vhost/*.conf; //其它站点
如上配置,如果nginx.conf中指定了ssl_protocols,这个就是默认的配置,如果这个文件中有多段server{},那么后面的会覆盖前面的。如果每个网站都要修改,就需要分别设置vhost中的所有的配置。
评论已关闭