sessionOptions.sni(仅限服务器)
🌐 sessionOptions.sni (server only)
- 类型:<Object>
一个将主机名映射到用于服务器名称指示(SNI)支持的 TLS 身份选项的对象。这对于服务器会话是必需的。特殊键 '*' 指定在没有其他主机名匹配时使用的默认/备用身份。每个条目可以包含:
🌐 An object mapping host names to TLS identity options for Server Name
Indication (SNI) support. This is required for server sessions. The
special key '*' specifies the default/fallback identity used when
no other host name matches. Each entry may contain:
keys<KeyObject> | <KeyObject[]> TLS 私钥。必需。certs<ArrayBuffer> | <ArrayBufferView> | <ArrayBuffer[]> | <ArrayBufferView[]> TLS 证书。必需。ca<ArrayBuffer> | <ArrayBufferView> | <ArrayBuffer[]> | <ArrayBufferView[]> 可选的 CA 证书覆盖。crl<ArrayBuffer> | <ArrayBufferView> | <ArrayBuffer[]> | <ArrayBufferView[]> 可选的证书撤销列表。verifyPrivateKey<boolean> 验证私钥。默认值:false。
const endpoint = await listen(callback, {
sni: {
'*': { keys: [defaultKey], certs: [defaultCert] },
'api.example.com': { keys: [apiKey], certs: [apiCert] },
'www.example.com': { keys: [wwwKey], certs: [wwwCert], ca: [customCA] },
},
}); 共享的 TLS 选项(例如 ciphers、groups、keylog 和 verifyClient)在会话选项的顶层指定,并适用于所有身份。每个 SNI 条目仅覆盖每个身份的证书字段。
🌐 Shared TLS options (such as ciphers, groups, keylog, and verifyClient)
are specified at the top level of the session options and apply to all
identities. Each SNI entry overrides only the per-identity certificate
fields.
SNI 映射可以在运行时使用 endpoint.setSNIContexts() 替换,该操作会以原子方式为新的会话交换映射,而现有会话则继续使用它们的原始身份。
🌐 The SNI map can be replaced at runtime using endpoint.setSNIContexts(),
which atomically swaps the map for new sessions while existing sessions
continue to use their original identity.