# 服务器名称指示

**服务器名称指示（Server Name Indication，SNI）**是[传输层安全](https://www.edgepedia.org/zh/transport-layer-security)（TLS）协议的一项扩展。客户端在TLS握手的第一条消息中声明它想要访问的主机名，使在同一IP地址上托管多个HTTPS网站的服务器能够为每个网站选择正确的TLS证书。该扩展于2003年在RFC 3546中首次规定，以方便管理“共置服务器”——即多个服务共用同一IP地址的情形——其现行规范为RFC 6066（2011年1月）<sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup><sup> • </sup><sup>[2](https://www.rfc-editor.org/info/rfc6066/)</sup>。

| 关键事实 | 详情 |
|---|---|
| 作用 | 客户端在客户端问候（ClientHello）中附带一个类型为“server_name”的扩展，携带它所要联系的服务器的主机名<sup>[2](https://www.rfc-editor.org/info/rfc6066/)</sup> |
| 解决的问题 | 让服务器能在同一IP地址上托管多个启用TLS的网站，并为每个网站出示各自的证书<sup>[3](https://blog.cloudflare.com/encrypted-sni/)</sup> |
| 标准化 | 最初在RFC 3546（2003年6月）中规定；经RFC 4366（2006年4月）和RFC 6066（2011年1月）修订<sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup><sup> • </sup><sup>[4](https://www.rfc-editor.org/info/rfc4366/)</sup> |
| 隐私弱点 | SNI在客户端问候中以明文携带，泄露目标域名；RFC 9849称其或许是TLS 1.3中仍未加密的最敏感信息<sup>[5](https://www.ietf.org/ietf-ftp/rfc/rfc9849.pdf)</sup> |
| 加密后继方案 | 加密SNI（ESNI）于2018年8月为TLS 1.3提出；其后继者加密客户端问候（ECH）已标准化为RFC 9849<sup>[6](https://www.usenix.org/conference/foci19/presentation/chai)</sup><sup> • </sup><sup>[5](https://www.ietf.org/ietf-ftp/rfc/rfc9849.pdf)</sup> |
| 浏览器支持 | 几乎所有浏览器、操作系统和Web服务器都支持SNI，只有一些非常古老的软件例外；自版本119起，Firefox默认启用ECH<sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup><sup> • </sup><sup>[8](https://support.mozilla.org/en-US/kb/faq-encrypted-client-hello?redirectlocale=en-US&redirectslug=faq-encrypted-client-hello-redirect-3)</sup> |

## 为什么需要它

在HTTPS中，TLS握手在HTTP对话开始之前进行，而握手发生在仅由[IP地址](https://www.edgepedia.org/zh/ip-address)和端口标识的TCP连接之上。当多个网站共用一台服务器和一个IP地址时，服务器仅凭连接无法判断客户端想要哪个网站，因此可能出示错误主机名的证书。如果证书上的名称与客户端试图访问的名称不匹配，浏览器就会报错，通常显示“您的连接不是私密连接”消息，并且通常会终止连接<sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup>。

在纯HTTP下不存在这个问题，因为客户端在TCP连接建立后的第一个HTTP请求中就会指明目标网站。SNI把这一指明动作移入了握手本身：客户端在客户端问候消息——TLS握手的第一步——中附带主机名，于是TLS过程就能到达正确的域名并收到正确的证书<sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup>。

尽管名为“服务器名称”，SNI所“指示”的其实是网站的**主机名**或域名，它可以与托管该网站的Web服务器的名称不同。与其他主机名一起托管在服务器上、没有自己独立IP地址的主机名，称为**虚拟主机名**<sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup>。

## 该扩展如何工作

RFC 6066对该扩展作了精确定义。TLS本身不提供让客户端告知服务器其所联系服务器名称的机制，因此客户端可以在扩展客户端问候（extended client hello）中附带一个类型为“server_name”的扩展。扩展数据包含一个ServerNameList，由若干ServerName条目组成，每个条目由一个名称类型和一个名称构成；规范中只规定并部署了“host_name”这一种变体<sup>[9](https://datatracker.ietf.org/doc/html/rfc6066.txt)</sup><sup> • </sup><sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup>。

其使用受若干规则约束。ServerNameList不得包含多于一个同一名称类型的名称。HostName字段中不允许出现字面IPv4和IPv6地址，DNS主机名的比较不区分大小写。如果服务器理解该扩展但不认识该名称，它应当以致命级别的unrecognized_name(112)警报中止握手，或者继续握手；不建议使用警告级别的警报，因为客户端对此的反应不可预测。使用该扩展来选择证书的服务器会在其服务器问候（server hello）中附带一个空的“server_name”扩展<sup>[9](https://datatracker.ietf.org/doc/html/rfc6066.txt)</sup>。

该扩展还与会话恢复相互作用。服务器在缓存中查找会话时可以使用server_name的内容，客户端在恢复请求中应当附带与最初完整握手时相同的server_name，如果名称不同，服务器不得接受恢复；恢复时，服务器不得在其服务器问候中附带server_name扩展<sup>[9](https://datatracker.ietf.org/doc/html/rfc6066.txt)</sup>。

## 服务器与客户端支持

在服务器端，Apache实现了基于SNI的基于名称的虚拟主机：当客户端在TLS握手中发送主机名时，Apache将其与候选虚拟主机的ServerName和ServerAlias进行比对，并使用所选主机的SSL配置完成握手。第一个（默认）虚拟主机必须允许至少一种TLSv1.0或更高版本的协议，否则Apache根本不会接受SNI信息。Apache v2.2.12配合OpenSSL v0.9.8j及更高版本支持SNI<sup>[10](https://cwiki.apache.org/confluence/spaces/HTTPD/pages/115522395/NameBasedSSLVHostsWithSNI)</sup><sup> • </sup><sup>[11](https://knowledge.digicert.com/general-information/desktop-mobile-browsers-that-support-sni)</sup>。

客户端的支持如今已近乎普遍。只有非常古老的[Internet Explorer](https://www.edgepedia.org/zh/internet-explorer)版本、旧版黑莓操作系统以及其他过时软件不支持；不支持SNI的浏览器可能无法访问某些共享托管网站，并会显示错误<sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup>。在非浏览器软件中采用较慢：2012年的一项调查发现，消费级浏览器与API客户端在声明支持SNI方面存在很大差距<sup>[12](https://paul.querna.org/articles/2012/09/06/adoption-of-tls-extensions/)</sup>。一些CDN出于兼容性原因推迟采用；Akamai多年来限制SNI的使用，以保持与[Windows XP](https://www.edgepedia.org/zh/windows-xp)等不支持SNI的旧版Windows兼容<sup>[13](https://files.research.cloudflare.com/publication/Fayed2021.pdf)</sup>。[Cloudflare](https://www.edgepedia.org/zh/cloudflare)的Universal SSL同样只支持使用SNI的客户端，遗留的非SNI客户端则通过标记为“Legacy”客户端支持的自定义证书来处理<sup>[14](https://developers.cloudflare.com/ssl/reference/browser-compatibility/)</sup>。

## 隐私问题

由于客户端问候在加密建立之前发送，SNI以明文传输。任何路径上的观察者——包括ISP、咖啡馆网络运营者、防火墙和审查者——都能读到客户端正在访问哪个域名<sup>[3](https://blog.cloudflare.com/encrypted-sni/)</sup><sup> • </sup><sup>[15](https://arxiv.org/abs/2101.04556)</sup>。这个问题随时间推移愈发明显：[TLS 1.3](https://www.edgepedia.org/zh/tls-1-3)（RFC 8446，2018年8月）对传输中的服务器证书加密，而[DNS over TLS](https://www.edgepedia.org/zh/dns-over-tls)和[DNS over HTTPS](https://www.edgepedia.org/zh/dns-over-https)等加密DNS隐藏了查询名称，于是SNI成了目标域名最后的明文泄露途径之一<sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup>。RFC 9849称明文SNI或许是TLS 1.3中仍未加密的最敏感信息<sup>[5](https://www.ietf.org/ietf-ftp/rfc/rfc9849.pdf)</sup>。

RFC 3546、RFC 4366和RFC 6066的“安全考虑”部分均未将明文传输标记为问题；起草这些文件时，同样的信息还可以通过DNS查询和明文证书等其他途径获得<sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup>。

## 从ESNI到ECH

2018年8月，一种名为ESNI（加密SNI）的新扩展被提出用于TLS 1.3，以修复服务器名称泄露问题，Cloudflare和Mozilla Firefox当年即推出了支持<sup>[6](https://www.usenix.org/conference/foci19/presentation/chai)</sup><sup> • </sup><sup>[7](https://www.cloudflare.com/learning/ssl/what-is-sni/)</sup>。ESNI只加密客户端问候中的SNI部分，使用通过Diffie-Hellman密钥交换导出的密钥；Cloudflare的实现每小时轮换服务器的ESNI密钥以实现前向保密，同时保留近期的密钥以应对DNS缓存延迟<sup>[3](https://blog.cloudflare.com/encrypted-sni/)</sup>。

ESNI被**加密客户端问候（Encrypted Client Hello，ECH）**取代，后者可以加密客户端问候的任意字段，甚至整条消息，而不只是SNI<sup>[16](https://www.mdpi.com/2673-8732/5/3/29)</sup>。ECH已标准化为RFC 9849。在ECH握手中，客户端发送一个外层客户端问候，其中包含一个共享的掩护SNI——例如Cloudflare上的cloudflare-ech.com——以及一个携带真实主机名的加密内层客户端问候；只有持有相应私钥的网关才能解密它<sup>[5](https://www.ietf.org/ietf-ftp/rfc/rfc9849.pdf)</sup><sup> • </sup><sup>[17](https://developers.cloudflare.com/ssl/edge-certificates/ech/)</sup>。ECH要求客户端从DNS HTTPS记录中获取服务器的ECH配置，因此它与加密DNS配合效果最佳<sup>[18](https://censorbib.nymity.ch/pdf/Niere2025b.pdf)</sup>。Firefox自版本98起支持ECH，自版本119起默认启用<sup>[19](https://wiki.mozilla.org/index.php?mobileaction=toggle_view_mobile&title=Security%2FEncrypted_Client_Hello)</sup><sup> • </sup><sup>[8](https://support.mozilla.org/en-US/kb/faq-encrypted-client-hello?redirectlocale=en-US&redirectslug=faq-encrypted-client-hello-redirect-3)</sup>。

## SNI过滤与审查

使虚拟主机成为可能的那个明文字段，同样使过滤成为可能。审查者可以通过客户端问候中的SNI扩展识别客户端正在访问的Web域名，随着TLS加密的普及，审查者已部署SNI过滤；研究中国基于SNI的审查的人员发现，ESNI结合加密DNS将使超过101,000个被审查网站更具抗审查性<sup>[6](https://www.usenix.org/conference/foci19/presentation/chai)</sup><sup> • </sup><sup>[20](https://www.usenix.org/system/files/foci19-paper_chai_0.pdf)</sup>。

ECH改变了这一平衡，其推广也备受争议。2025年，研究人员报告称俄罗斯已开始成功审查ECH连接：俄罗斯的TSPU设备通过分析外层SNI字段来阻断发往Cloudflare的ECH流量，而由于Cloudflare的部署使用静态外层SNI，审查得以奏效；研究发现非Cloudflare的ECH部署几乎不存在<sup>[21](https://petsymposium.org/foci/2025/foci-2025-0016.php)</sup><sup> • </sup><sup>[18](https://censorbib.nymity.ch/pdf/Niere2025b.pdf)</sup>。民主与技术中心指出，ECH的设计准则是“不显眼”，以便在部署广泛后加密连接变得无法区分，但在实践中实现这种一致性已被证明十分困难<sup>[22](https://cdt.org/insights/do-not-stick-out-the-dynamics-of-the-ech-rollout/)</sup>。

设计SNI加密本身就很困难。RFC 8744记录了早期经安全审查后被否决的若干提案，包括：对手重放加密SNI值以揭示隐藏服务的剪切粘贴攻击、广泛共享对称密钥的脆弱性、对前端解密组件的拒绝服务压力，以及加密握手变得可被检测并遭阻断的风险<sup>[1](https://www.rfc-editor.org/info/rfc8744/)</sup>。

## References

1. [RFC 8744: Issues and Requirements for Server Name Identification (SNI) Encryption in TLS, RFC Editor](https://www.rfc-editor.org/info/rfc8744/)
2. [RFC 6066: Transport Layer Security (TLS) Extensions: Extension Definitions, RFC Editor](https://www.rfc-editor.org/info/rfc6066/)
3. [Encrypt it or lose it: how encrypted SNI works, Cloudflare Blog](https://blog.cloudflare.com/encrypted-sni/)
4. [RFC 4366: Transport Layer Security (TLS) Extensions, RFC Editor](https://www.rfc-editor.org/info/rfc4366/)
5. [RFC 9849: TLS Encrypted Client Hello, IETF](https://www.ietf.org/ietf-ftp/rfc/rfc9849.pdf)
6. [On the Importance of Encrypted-SNI (ESNI) to Censorship Circumvention, USENIX FOCI 2019](https://www.usenix.org/conference/foci19/presentation/chai)
7. [What Is SNI? How TLS Server Name Indication Works, Cloudflare](https://www.cloudflare.com/learning/ssl/what-is-sni/)
8. [Encrypted Client Hello (ECH) - Frequently asked questions, Firefox Help](https://support.mozilla.org/en-US/kb/faq-encrypted-client-hello?redirectlocale=en-US&redirectslug=faq-encrypted-client-hello-redirect-3)
9. [RFC 6066 (full text), IETF Datatracker](https://datatracker.ietf.org/doc/html/rfc6066.txt)
10. [NameBasedSSLVHostsWithSNI, Apache HTTPD Wiki](https://cwiki.apache.org/confluence/spaces/HTTPD/pages/115522395/NameBasedSSLVHostsWithSNI)
11. [Desktop and Mobile Browsers That Support SNI, DigiCert Knowledge Base](https://knowledge.digicert.com/general-information/desktop-mobile-browsers-that-support-sni)
12. [Adoption of TLS Extensions, Paul Querna (2012)](https://paul.querna.org/articles/2012/09/06/adoption-of-tls-extensions/)
13. [The Ties that un-Bind: Decoupling IP from web services and sockets for robust addressing agility at CDN-scale, Cloudflare Research](https://files.research.cloudflare.com/publication/Fayed2021.pdf)
14. [Browser compatibility, Cloudflare SSL/TLS docs](https://developers.cloudflare.com/ssl/reference/browser-compatibility/)
15. [Masking Host Identity on Internet: Encrypted TLS/SSL Handshake, arXiv](https://arxiv.org/abs/2101.04556)
16. [Encrypted Client Hello Is Coming: A View from Passive Measurements, MDPI](https://www.mdpi.com/2673-8732/5/3/29)
17. [ECH Protocol, Cloudflare SSL/TLS docs](https://developers.cloudflare.com/ssl/edge-certificates/ech/)
18. [Encrypted Client Hello (ECH) in Censorship Circumvention, PoPETs/FOCI 2025](https://censorbib.nymity.ch/pdf/Niere2025b.pdf)
19. [Security/Encrypted Client Hello, MozillaWiki](https://wiki.mozilla.org/index.php?mobileaction=toggle_view_mobile&title=Security%2FEncrypted_Client_Hello)
20. [On the Importance of Encrypted-SNI (ESNI) to Censorship Circumvention (full paper), USENIX](https://www.usenix.org/system/files/foci19-paper_chai_0.pdf)
21. [Encrypted Client Hello (ECH) in Censorship Circumvention, PoPETs FOCI 2025 proceedings page](https://petsymposium.org/foci/2025/foci-2025-0016.php)
22. [Do Not Stick Out: The Dynamics of the ECH Rollout, Center for Democracy and Technology](https://cdt.org/insights/do-not-stick-out-the-dynamics-of-the-ech-rollout/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Network defense and threats › TLS and transport-layer security

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/server-name-indication

English original: https://www.edgepedia.org/server-name-indication
