ssl - NGINX HTTPS 服务器 - SSL_ERROR_BAD_CERT_DOMAIN

标签 ssl nginx https

我有一个在 EC2 实例上运行的 NGINX 服务器,我正在该服务器上实现 HTTPS。我在另一个网站上生成了 SSL 证书并将其放在我的服务器上。重新启动服务器,它仍然可以正常运行,但有两个问题(我的域是 hbesco.com.br,这是我为证书请求输入的通用名称):

默认输入的不是 HTTPS,而是 HTTP。另外,如果我像 https://hbesco.com.br 那样强制执行它,没问题。但是对于 https://www.hbesco.com.br ,它给了我以下错误:

无法与对等方安全通信:请求的域名与服务器的证书不匹配。 HTTP 严格传输安全:false HTTP 公钥固定:false 证书链:-----BEGIN CERTIFICATE----- (...)

我的 NGINX 站点可用/默认设置如下:

server {
       listen 443 default_server;

       ssl on;
       ssl_certificate /usr/share/nginx/certificado-2048/CertificadoSSL.crt;
       ssl_certificate_key /usr/share/nginx/certificado-2048/CertificadoSSL.key;

        server_name hbesco.com.br;
        passenger_enabled on;
        rails_env    production;
        root         /home/ubuntu/hybrazil/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen 80;

        server_name hbesco.com.br;
        passenger_enabled on;
        rails_env    production;
        root         /home/ubuntu/hybrazil/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

关于为什么当我输入“hbesco.com.br”时它首先进入 http,以及为什么当它之前有 www 时,它给我这个错误有什么想法吗?

最佳答案

It doesn't enter as HTTPS as default, it goes for HTTP

您需要添加重写规则以强制将访问者从 http 重定向到 https:

server {
        listen 80;
        server_name hbesco.com.br;
        rewrite     ^   https://$server_name$request_uri? permanent;
}

Unable to communicate securely with peer: requested domain name does not match the server’s certificate.

这意味着证书中只列出了 hbesco.com.br。您可以使用任何 ssl 检查器进行检查。

关于ssl - NGINX HTTPS 服务器 - SSL_ERROR_BAD_CERT_DOMAIN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45306792/

相关文章:

ssl - Spring Boot 1.4.1 SSL trustAnchors 异常

ruby-on-rails - 在本地主机中使用 Apache\Phusion Passenger 为虚拟主机设置 SSL 证书时出现问题

django - $sent_http_content_language 不起作用

django - docker-compose 中的collectstatic权限问题

apache - 子域和其他域的 SSL 证书

windows - 生成自签名证书后 Apache 无法启动

nginx - 登录错误URL后的phpmyadmin

javascript - 使用 JavaScript 检测 HTTPS

nginx - 为什么在端口 80 上运行 Varnish 仅用于 HTTPS 设置?

php - 如何在单个文件上强制使用 HTTPS? (PHP)