使用 Nginx 和 Chrome 的通配符 *.localhost SSL

tho*_*edb 5 nginx google-chrome ssl-certificate

我试图*.localhost为 HTTP 和 HTTPS设置一个通配符,Nginx 将请求代理到localhost:3000. DNSmasq 用于解析*.localhost127.0.0.1.

HTTP 一切正常,但 HTTPS 连接在 Google Chrome 中收到以下错误:

There are issues with the site's certificate chain (net::ERR_CERT_COMMON_NAME_INVALID).
Run Code Online (Sandbox Code Playgroud)

该证书是我通过设置添加到 Chrome 的自签名证书,并使用以下命令生成:

openssl req -x509 -sha256 -newkey rsa:2048 -keyout localhost.key -out localhost.crt -days 3650 -nodes
Run Code Online (Sandbox Code Playgroud)

Subject如下:

Subject: C=AU, ST=Western Australia, L=Perth, O=Zephon, CN=*.localhost
Run Code Online (Sandbox Code Playgroud)

我的 Nginx 配置如下:

server {
    listen       80;
    listen       443 ssl; 

    server_name  localhost;

    ssl_certificate /etc/nginx/ssl/localhost.crt;
    ssl_certificate_key /etc/nginx/ssl/localhost.key;

    location / {
        proxy_pass          http://localhost:3000;
        proxy_http_version  1.1;
        proxy_set_header    Host             $host;
        proxy_set_header    Upgrade          $http_upgrade;
        proxy_set_header    Connection       "upgrade";
        proxy_set_header    X-Real-IP        $remote_addr;
        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header    X-Client-Verify  SUCCESS;
        proxy_set_header    X-Client-DN      $ssl_client_s_dn;
        proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
        proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
        proxy_read_timeout 1800;
        proxy_connect_timeout 1800;
    }
}
Run Code Online (Sandbox Code Playgroud)

tho*_*edb 9

因此,最终的答案似乎是您根本无法为*.localhostChrome 接受的证书创建证书。

我的解决方案是改为使用*.dev.localhost,这很有效。