在 javascript 中检测 SNI(服务器名称指示)浏览器支持

2022-01-25 00:00:00 ssl ssl-certificate javascript

我希望能够检测浏览器是否支持 SNI - 服务器名称指示.我希望将不合规的客户重定向到不同的地址.

I want to be able to detect if the browser support SNI - Server Name Indication. I'm hoping to redirect non compliant clients to a different address.

我正在考虑通过 SSL 加载一些内容并确保其安全传输.否则浏览器不支持 SNI.这可以做到吗?

I was thinking of loading some content through SSL and make sure it was transfered securely. Otherwise the browser doesn't support SNI. Can this be done?

推荐答案

你可以设置一个支持 SNI 的服务器,提供两个主机名,在你需要 SNI 的地方和一个作为后备解决方案的地方,两者都提供他们的名字正在托管.

You could set up a server that supports SNI, serving two host names, on where you require SNI and one that's a fallback solution, both serving the name that they are hosting.

类似的东西:

  • https://www.example.com/name 返回表示 I'm www.example.com
  • https://www.example.net/name 返回 I'm www.example.net(并且需要 SNI).
  • https://www.example.com/name returns a representation saying I'm www.example.com
  • https://www.example.net/name returns I'm www.example.net (and requires SNI).

如果您向 https://www.example.net/name 发出 XHR 请求并返回 www.example.com,则浏览器不会支持SNI.

If you make an XHR request to https://www.example.net/name and it returns www.example.com, then the browser doesn't support SNI.

相关文章