回答
收藏
分享
举报
NGINX SNI配置失败,同一个服务器配置不同域名不同证书
提问于2023-10-23 22:00

浏览 1.7k

文章标签

环境准备如下

  • 有一台华为云服务器,绑定了公网ip地址6.6.6.6
  • 申请了两个域名www.testa.com www.testb.com 分别解析到该ip地址
  • 申请了两个单项认证的测试证书servera.crt 和 serverb.crt
  • 该服务器上部署了两个服务A B

Nginx配置如下

server {
        listen 443 ssl;
        server_name www.testa.com ;
        ssl_certificate   /tmp/servera.crt;
        ssl_certificate_key /tmp/servera.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;

        location / {
            root  /opt/starting;
            index index.html index.htm;
        }
     }
     
  server {
        listen 443 ssl;
        server_name www.testb.com
        root /home/weixinapp;
        index testtttttt.txt;
        ssl_certificate   /tmp/serverb.pem;
        ssl_certificate_key /tmp/serverb.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        location / {
        }

    }
  • 从浏览器访问 https://www.testb.com 可以正常获取到testtttt.txt内的信息,访问https://www.testa.com 谷歌浏览器报错
此网站无法提供安全连接testa.com 发送的响应无效。
ERR_SSL_PROTOCOL_ERROR
  • 从本地curl 结果如下
* ALPN: offers h2
* ALPN: offers http/1.1
* (304) (OUT), TLS handshake, Client hello (1):
* error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version
* Closing connection 0
curl: (35) error:1404B42E:SSL routines:ST_CONNECT:tlsv1 alert protocol version
  • nginx 打开debug 报错日志如下
2023/10/23 21:56:14 [debug] 2893191#0: epoll: fd:17 ev:0001 d:00005565E69C8E80
2023/10/23 21:56:14 [debug] 2893191#0: accept on 0.0.0.0:443, ready: 0
2023/10/23 21:56:14 [debug] 2893191#0: posix_memalign: 00005565E6A3F410:512 @16
2023/10/23 21:56:14 [debug] 2893191#0: *224 accept: XXXX:62296 fd:37
2023/10/23 21:56:14 [debug] 2893191#0: *224 event timer add: 37: 60000:35592117776
2023/10/23 21:56:14 [debug] 2893191#0: *224 reusable connection: 1
2023/10/23 21:56:14 [debug] 2893191#0: *224 epoll add event: fd:37 op:1 ev:80002001
2023/10/23 21:56:14 [debug] 2893191#0: timer delta: 74848
2023/10/23 21:56:14 [debug] 2893191#0: worker cycle
2023/10/23 21:56:14 [debug] 2893191#0: epoll timer: 60000
2023/10/23 21:56:14 [debug] 2893191#0: epoll: fd:37 ev:2019 d:00005565E69C94D9
2023/10/23 21:56:14 [debug] 2893191#0: epoll_wait() error on fd:37 ev:2019
2023/10/23 21:56:14 [debug] 2893191#0: *224 http check ssl handshake
2023/10/23 21:56:14 [debug] 2893191#0: *224 http recv(): 1
2023/10/23 21:56:14 [debug] 2893191#0: *224 https ssl handshake: 0x16
2023/10/23 21:56:14 [debug] 2893191#0: *224 tcp_nodelay
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL server name: "www.testa.com"
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL ALPN supported by client: h2
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL ALPN supported by client: http/1.1
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL ALPN selected: http/1.1
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL_do_handshake: -1
2023/10/23 21:56:14 [debug] 2893191#0: *224 SSL_get_error: 5
2023/10/23 21:56:14 [info] 2893191#0: *224 peer closed connection in SSL handshake (104: Connection reset by peer) while SSL handshaking, client: XXXXXX, server: 0.0.0.0:443
2023/10/23 21:56:14 [debug] 2893191#0: *224 close http connection: 37
2023/10/23 21:56:14 [debug] 2893191#0: *224 event timer del: 37: 35592117776
2023/10/23 21:56:14 [debug] 2893191#0: *224 reusable connection: 0
2023/10/23 21:56:14 [debug] 2893191#0: *224 free: 00005565E6A3F410, unused: 120
2023/10/23 21:56:14 [debug] 2893191#0: timer delta: 0
2023/10/23 21:56:14 [debug] 2893191#0: worker cycle
2023/10/23 21:56:14 [debug] 2893191#0: epoll timer: -1

麻烦大神帮看下需要需要怎么配置或者排查,可以实现一台服务器,两个域名、两套证书、两个服务,通过不同域名的443端口访问不同的服务

已修改于2023-10-23 22:00



写下您的回答
发表回答
全部回答(0)

按点赞数排序

按时间排序

提问者
sunguangning
这家伙很懒还未留下介绍~
0
文章
1
问答
0
粉丝
相关问答

未遇到过。是worker进程还是master进程?新的worker进程无法正常使用是什么意思?是TCP连接建立不起来?还是返回的http response不对?

点赞 0
浏览 4k

可以的,试试 client_body_in_file_only 或者 client_body_in_single_buffer 这两个指令应该都可以。

点赞 0
浏览 3.8k