nginx ssl拒绝不匹配的server_name请求

时间:2018-04-10 03:12:50

标签: ssl nginx sni

server {
        lerver {
        listen       443 ssl;
        server_name  proxy.test.com;

        ssl_certificate      sni.crt;
        ssl_certificate_key  sni.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }

    server {
        listen       443 default_server ssl;
        server_name  test.com; 

        ssl_certificate      test-cn.crt;
        ssl_certificate_key  test-cn.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;

        location / {
            root   html;
            index  index.html index.htm;
        }

      }

我希望使用ssl配置nginx以遵守SNI请求(来自客户端的ClientHello中的server_name指令),拒绝不匹配的server_name SNI请求的握手,并为非SNI请求提供默认证书(ClientHello没有server_name指令)。

通过以上配置,我可以让nginx兑换proxy.test.com的SNI请求。但对于具有SNI请求的ClientHello为invalid-domain.com,对于没有SNI请求的ClientHello,使用默认服务器块。如何让nginx拒绝对invalid-domain.com的SNI请求,同时为非SNI请求提供默认服务器块?

1 个答案:

答案 0 :(得分:0)

我遇到了 nginx 的这个新功能,如果请求的 server_name 与您在服务器指令中列出的内容不匹配,它甚至会在发送 server_hello 之前丢弃请求。我认为这将有助于完成您想要做的事情。除非 SNI 与 proxy.test.com 匹配,否则以下配置应将所有请求丢弃到 443。

server {
    listen               443 ssl;
    ssl_reject_handshake on;
}
server {
        listen       443 ssl;
        server_name  proxy.test.com;

        ssl_certificate      sni.crt;
        ssl_certificate_key  sni.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;

        location / {
            root   html;
            index  index.html index.htm;
        }
 }

链接到文档。

ssl_reject_handshake