每个虚拟主机的 nginx ssl 配置

Mac*_*ski 3 ssl nginx ssl-certificate ssl-certificate-errors

我正在将配置从单个主机切换到 nginx 服务器上的多个虚拟主机。在我更改之前,ssl 可以正常工作,但是在添加了几个虚拟主机后,每个虚拟主机都有唯一的域名 - 因此 - 不同的证书,ssl 不想工作。

我原来的配置是:

# fragment of nginx.conf file
http {
    # ...
    ssl_certificate_key /path/to/privkey.pem;
    ssl_certificate     /path/to/fullchain.pem;
    ssl_dhparam         /path/to/dhparam;
    # ...
}
Run Code Online (Sandbox Code Playgroud)

因此,这是 nginx 服务器的单个证书。

添加几个虚拟主机后,我希望他们为他们的域提供他们自己的、正确的证书。所以我从主nginx.conf文件中删除了所有与 ssl 相关的参数,并将它们添加到虚拟主机文件中,如下所示:

# fragment of sites-enabled/my.server.com file
server {
   listen 443 ssl;
   root "/var/www/my.server.com/";
   server_name my.server.com www.my.server.com;
   location / {
       try_files $uri $uri/ /index.html;

   }
   ssl_certificate_key /path/to/my/server/com/privkey.pem;
   ssl_certificate     /path/to/my/server/com/fullchain.pem;
   ssl_dhparam         /path/to/my/server/com/dhparam;
}
Run Code Online (Sandbox Code Playgroud)

重新加载 nginx 后,我无法连接到这些虚拟主机:

# curl https://my.server.com 
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.

# openssl s_client -connect my.server.com:443
CONNECTED(00000003) 140524682454680:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:s23_lib.c:177:
--- no peer certificate available
--- No client certificate CA names sent
--- SSL handshake has read 0 bytes and written 305 bytes
--- New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1488541876
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
Run Code Online (Sandbox Code Playgroud)

对我来说,看起来真的像 nginx 无法找到/读取证书文件,但事实并非如此,因为路径与没有虚拟主机的配置完全相同。

看了之后/var/logs/nginx/error.log我也发现了这一行:

*39 no "ssl_certificate" is defined in server listening on SSL port while SSL handshaking
Run Code Online (Sandbox Code Playgroud)

我确信我所缺少的东西真的很小而且很愚蠢。谁能看到我做错了什么?

Mac*_*ski 5

原来,有至少一个已启用其绑定到443端口,并没有使用SSL正确配置(虚拟主机ssl_certificate_keyssl_certificate参数缺乏)。

我不知道为什么,但 nginx 没有抱怨这个,而是 - 其他虚拟主机坏了。