在我的 nginx 服务器上设置 SSL/HTTPS 后不安全

Use*_*ame 2 ssl nginx https

我正在尝试在我的网站上设置 HTTPS/SSL test.example.com

我编辑了我的文件,/etc/nginx/sites-enabled/my_site以便server {}块的顶部是这个。

server {
    listen 443;
    ssl on;
    ssl_certificate /etc/ssl/cert_chain.crt;
    ssl_certificate_key /etc/ssl/example.key;
    server_name test.example.com;
    error_log /var/log/nginx/debug.log debug;

    ... Rest of code ...
}
Run Code Online (Sandbox Code Playgroud)

我跑了nginx restart。但是如果我https://test.testexample.com在 Chromium 中访问,我的浏览器会警告我与该站点的连接不安全。

铬错误:

Your connection is not private
Attackers might be trying to steal your information from test.example.com (for example, passwords, messages, or credit cards). Learn more
NET::ERR_CERT_COMMON_NAME_INVALID

This server could not prove that it is test.example.com; its security certificate is from example.com. This may be caused by a misconfiguration or an attacker intercepting your connection.
Run Code Online (Sandbox Code Playgroud)

我的证书是由 Comodo 颁发的。我正在按照 Namecheap 的指南将 SSL 集成到我的网站中。第三步:https : //www.namecheap.com/support/knowledgebase/article.aspx/9419/0/nginx

Ste*_*ich 7

NET::ERR_CERT_COMMON_NAME_INVALID ...
该服务器无法证明它是 test.example.com;它的安全证书来自example.com。这可能是由于配置错误或攻击者拦截了您的连接造成的。

服务器返回的证书与 URL 中的名称不匹配。根据此描述,您已为其订购了证书,example.com但尝试访问该站点,因为test.example.com该站点不是颁发证书的域。

此问题可能是由于对 URL 中的域与证书的比较如何工作的错误理解。一般来说:

  • 证书仅对证书的主题备用名称部分中明确提到的域有效(Chrome 忽略 CN)。这意味着example.com不匹配test.example.com
  • 如果您有一个通配符,则只能有一个*,它必须是最左边的标签,并且它只匹配域的一个部分,即证书 for *.example.comwill 匹配www.example.comtest.example.com但不匹配www.test.example.com