V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
KyonLi
V2EX  ›  问与答

Nginx 配置多个 https 站点为什么只有第一个可以正常访问

  •  
  •   KyonLi · 2017-09-16 10:08:41 +08:00 · 6025 次点击
    这是一个创建于 2413 天前的主题,其中的信息可能已经有所发展或是发生改变。

    /etc/nginx/sites-enabled 下有 3 个 vHost:

    0-block 2-telegram-bot 3-status

    # 0-block
    
    server {
        listen 80 default_server;
        server_name _;
        return 403;
    }
    
    # 2-telegram-bot
    
    server {
        listen 80;
        server_name api.example.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name api.example.com;
        ssl_certificate /etc/nginx/cert/api.cert;
        ssl_certificate_key /etc/nginx/cert/api.key;
    
        location / {
            proxy_pass https://api.telegram.org;
        }
    }
    
    # 3-status
    
    server {
        listen 80;
        server_name status.example.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name status.example.com;
        ssl_certificate /etc/nginx/cert/status.cert;
        ssl_certificate_key /etc/nginx/cert/status.key;
    
        location / {
            proxy_pass http://127.0.0.1:19999;
        }
    }
    

    2-telegram-bot 可以正常访问。3-status Safari 下正常,Chrome 提示 ERR_SSL_PROTOCOL_ERROR。

    禁用掉 2 后 3 恢复正常,也就是排在最前面的 https 站点是正常的。

    Nginx 版本

    nginx version: nginx/1.6.2 (Ubuntu) TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module

    求教这是什么情况,或给出搜索关键词也行,谢谢!

    第 1 条附言  ·  2017-09-16 11:09:54 +08:00
    Nginx debug log:

    [debug] 10870#0: *1 SSL_do_handshake: -1
    [debug] 10870#0: *1 SSL_get_error: 2
    [debug] 10870#0: *1 reusable connection: 0
    [debug] 10870#0: *1 post event 00007F3C0B5F83A8
    [debug] 10870#0: *1 delete posted event 00007F3C0B5F83A8
    [debug] 10870#0: *1 SSL handshake handler: 0
    [debug] 10870#0: *1 SSL_do_handshake: 0
    [debug] 10870#0: *1 SSL_get_error: 1
    [info] 10870#0: *1 SSL_do_handshake() failed (SSL: error:14094417:SSL routines:SSL3_READ_BYTES:sslv3 alert illegal parameter:SSL alert number 47) while SSL handshaking, client: *.*.*.*, server: 0.0.0.0:443
    [debug] 10870#0: *1 close http connection: 13
    [debug] 10870#0: *1 SSL_shutdown: 1
    [debug] 10870#0: *1 event timer del: 13: 1505530638234
    [debug] 10870#0: *1 reusable connection: 0
    [debug] 10870#0: *1 free: 00007F3C0B5C17D0, unused: 0
    [debug] 10870#0: *1 free: 00007F3C0B5BBD00, unused: 116

    加上 ssl_protocols TLSv1.2; 错误不变。
    10 条回复    2017-09-18 14:58:44 +08:00
    keyfunc
        1
    keyfunc  
       2017-09-16 10:13:21 +08:00
    检查 OPENSSL 版本,看看是否支持 SNI
    KyonLi
        2
    KyonLi  
    OP
       2017-09-16 10:20:26 +08:00
    @keyfunc OpenSSL 1.0.1f > 0.9.8 应该支持 SNI 吧
    dndx
        3
    dndx  
       2017-09-16 10:38:59 +08:00
    用 --with-debug 编译 NGINX,打开 debug 日志,可以看出来握手过程和具体失败原因。
    lslqtz
        4
    lslqtz  
       2017-09-16 11:00:34 +08:00
    ERR_SSL_PROTOCOL_ERROR
    这是协商错误吧...
    KyonLi
        5
    KyonLi  
    OP
       2017-09-16 11:26:43 +08:00
    @dndx
    SSL: error:14094417:SSL routines:SSL3_READ_BYTES:sslv3 alert illegal parameter:SSL alert number 47
    只启用 TLSv1.2 也是如此

    @lslqtz 但为什么作为第一个 https vHost 就不会出错...
    Loyalsoldier
        6
    Loyalsoldier  
       2017-09-16 11:29:12 +08:00
    更新一下 Nginx,这个版本太旧了
    wql
        7
    wql  
       2017-09-16 11:32:36 +08:00 via Android
    cipher 问题
    KyonLi
        8
    KyonLi  
    OP
       2017-09-18 14:27:13 +08:00
    @Loyalsoldier
    通过 nginx 官方预编译包更新到了 1.9.12 ,问题依旧。

    @wql
    默认配置和 Mozilla SSL Configuration Generator 生成的配置都试过了,还是不行

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    ssl_protocols TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
    ssl_prefer_server_ciphers on;
    Loyalsoldier
        9
    Loyalsoldier  
       2017-09-18 14:32:33 +08:00
    @KyonLi #8 Nginx v1.12 都出来了…… v1.9 都已经废弃了
    KyonLi
        10
    KyonLi  
    OP
       2017-09-18 14:58:44 +08:00
    @Loyalsoldier VPS 装的 ubuntu 15.04 ,换系统要掏 10 刀,64M RAM 加上超售严重从源码编译会中途失败,1.9 已经是我能找到的最新的版本了。主要想确认一下是不是我配置的问题,第一次用 Nginx 就这么虐心要有阴影了...
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1007 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:49 · PVG 03:49 · LAX 12:49 · JFK 15:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.