惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

linux on 打工人日志

nginx 配置和编译 nginx ssh-key connection exception centos7.9 网络配置 nginx 编译参数详解 nginx 重写规则 rewrite模块 nginx.conf 配置文件详解 nginx 日志格式整理 linux系统开启root权限 nginx 汇总
使用TLSv1.3 升级nginx和openssl
2025-07-22 · via linux on 打工人日志

介绍

TLS v1.3(Transport Layer Security version 1.3)是传输层安全协议的最新正式版本,用于在计算机网络中提供加密通信。它由 IETF(Internet Engineering Task Force)2018 年 8 月正式发布,是对 TLS v1.2 的重大改进。
tls_ssl_development
由于原有老的nginx版本不支持新的TLSv1.3,需要升级nginx和openssl。


🔐 TLS 的用途

TLS 常用于以下场景:

  • HTTPS(浏览器访问网站)
  • 邮件客户端与服务器通信(如 IMAP/SMTP over TLS)
  • VPN、聊天工具等需要安全传输的场合

✨ 相比 TLS 1.2,TLS 1.3 有哪些主要改进?

特性TLS 1.2TLS 1.3
握手轮数至少 2 次往返最多 1 次往返,支持 0-RTT
加密套件多且复杂,包含弱算法简化,仅支持强加密算法
前向保密可选强制启用
加密内容一部分未加密握手后所有内容都加密,包括证书
安全性存在旧漏洞(如 BEAST、POODLE)移除已知不安全特性
性能较慢更快(特别是在移动网络)

🔧 移除的内容(相比 TLS 1.2)

  • RSA 密钥交换(只保留 ECDHE/DHE)
  • 不安全的加密算法(如 RC4、3DES、MD5)
  • 静态密钥协商、不再支持非前向保密
  • 会话恢复机制被简化为基于票据(session tickets)

✅ TLS 1.3 的优势总结

  • 更安全:移除所有已知不安全或弱加密机制
  • 更快:减少握手延迟,适合移动/高延迟网络
  • 更私密:握手阶段信息也加密,防监听分析

💡 哪些应用已经支持 TLS 1.3?

  • 现代浏览器(Chrome、Firefox、Safari、Edge)
  • 常用 Web 服务器(Nginx、Apache、LiteSpeed)
  • 后端库和操作系统(OpenSSL 1.1.1+、BoringSSL、Windows 10+)

下载编译

首先编译openssl

首先,下载 OpenSSL 的源代码,建议下载 1.1.1 或更高版本,因为这些版本支持 TLSv1.3。我这里是放到/usr/local/src

1cd /usr/local/src
2sudo wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz
3sudo tar -xvzf openssl-1.1.1l.tar.gz
4cd openssl-1.1.1l

在编译 OpenSSL 时,你需要指定安装目录。通常,OpenSSL 会安装到 /usr/local/ssl,这样不会干扰系统的默认 OpenSSL 版本。当然你也可以选择你自己的喜欢的位置,我这里就安装在/usr/local/ssl

1sudo ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl

安装和配置环境

将编译并安装 OpenSSL 到指定目录 /usr/local/ssl

1sudo make
2sudo make install

编辑 /etc/profile 或用户的 .bashrc 文件,添加以下内容:

1export PATH=/usr/local/ssl/bin:$PATH
2export LD_LIBRARY_PATH=/usr/local/ssl/lib:$LD_LIBRARY_PATH
3export C_INCLUDE_PATH=/usr/local/ssl/include:$C_INCLUDE_PATH
4export CPLUS_INCLUDE_PATH=/usr/local/ssl/include:$CPLUS_INCLUDE_PATH

加载新的环境变量

1source /etc/profile  # 或者 source ~/.bashrc

检查 OpenSSL 安装

编译nginx

下载和解压 Nginx 源代码

1cd /usr/local/src
2sudo wget https://nginx.org/download/nginx-1.29.0.tar.gz
3sudo tar -zxvf nginx-1.29.0.tar.gz
4cd nginx-1.29.0

在编译 Nginx 时,指定 OpenSSL 的安装路径。确保在配置时使用 –with-openssl 参数,指向 OpenSSL 源代码的路径。/usr/local/src/openssl-1.1.1l

1sudo ./configure --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf \
2--http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log \
3--with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module \
4--with-http_image_filter_module --with-http_stub_status_module --with-pcre-jit \
5--with-openssl=/usr/local/src/openssl-1.1.1l --with-debug

注意完成这一步,如果要实现不停机升级nginx千万不要执行make install

备份老的nginx

1which nginx
2cd /usr/sbin
3sudo cp nginx nginx.bak

替换新的nginx

1cd /usr/local/src/nginx-1.29.0
2make
3cp objs/nginx /usr/sbin/nginx

测试新的nginx

1nginx -t
2nginx -s reload
3nginx -V

配置TLSv1.3

打开 Nginx 配置文件 /etc/nginx/nginx.conf 或你相关的站点配置文件,确保启用了 TLSv1.3。

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256:TLS_AES_256_CCM_SHA384';
    ssl_prefer_server_ciphers off;

    # Other server configurations...
}

测试新配置

重启nginx

使用 openssl s_client 来验证是否启用了 TLSv1.3

1openssl s_client -connect example.com:443 -tls1_3

或者浏览器访问
chrome

总结

  • 编译 OpenSSL 1.1.1 并将其安装到 /usr/local/ssl。
  • 重新编译 Nginx,确保它链接到新安装的 OpenSSL。
  • 在 Nginx 配置文件 中启用 TLSv1.3 支持。
  • 验证配置 并重新加载 Nginx。