将nginx配置为从单个服务器服务HTTP和HTTPS站点时出现问题

将nginx配置为从单个服务器服务HTTP和HTTPS站点时出现问题,http,nginx,https,virtualhost,Http,Nginx,Https,Virtualhost,我有一个单一的服务器,主机很少的网站 为了减少问题,我们假设它们只有两个: http://www.example-A.com https://www.example-B.com 站点A只提供HTTP连接,而站点B有自己的SSL证书并提供安全连接 我的配置文件如下所示(相关部分): 现在如果我连接到http://www.example-A.com一切正常。 同时连接到https://www.example-B.com按预期工作。 连接到http://www.example-B.com导致重定向到h

我有一个单一的服务器,主机很少的网站
为了减少问题,我们假设它们只有两个:
http://www.example-A.com

https://www.example-B.com

站点
A
只提供HTTP连接,而站点
B
有自己的SSL证书并提供安全连接

我的配置文件如下所示(相关部分):

现在如果我连接到
http://www.example-A.com
一切正常。
同时连接到
https://www.example-B.com
按预期工作。
连接到
http://www.example-B.com
导致重定向到
https://www.example-B.com

到目前为止还不错

现在,如果我尝试安全连接到
a
https://www.example-A.com

我希望服务器拒绝连接

相反,我得到的是浏览器警告连接不安全。
当我继续前进时,我降落在域
https://www.example-A.com
但是提供了
www.example-B.com
的内容

如果我添加到配置中

    server
    {
        listen 443 ssl;

        server_name www.example-A.com;

        return 444;
    }
然后,尝试与
a
的安全连接会按预期失败

但也连接到
https://www.example-B.com
失败


我错过了什么?为什么不遵守
server\u name
指令

如何在HTTP中为
A
服务,在HTTPS中为
B
服务,并阻止不受支持的到
A
的HTTPS连接


我在跑步

$ nginx -V
nginx version: nginx/1.12.2
built with OpenSSL 1.1.0d  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local --sbin-path=/usr/local/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --with-http_ssl_module --with-http_stub_status_module --with-pcre=../pcre-8.37 --add-module=../headers-more-nginx-module-0.33

最佳做法是使用
默认\u服务器
,此指令指定使用服务器。如果主机名未知,您可以将其用作一个“包罗万象”来处理与
服务器名
值不匹配的任何主机名。如果没有此选项,第一台服务器将被视为默认服务器

e、 g


如果我添加此
服务器
块,则连接到
www.example-b.com
失败您的重定向应该包括
.com
对吗?i、 e.
https://www.example-b.com$request_uri
$ nginx -V
nginx version: nginx/1.12.2
built with OpenSSL 1.1.0d  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local --sbin-path=/usr/local/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --with-http_ssl_module --with-http_stub_status_module --with-pcre=../pcre-8.37 --add-module=../headers-more-nginx-module-0.33
# 444 Close connection Without Response on requests without hostname
server {
    listen 80 default_server;
    listen 443 ssl default_server;
    server_name _;
    ssl_certificate /path/to/ssl/example.com.crt;
    ssl_certificate_key /path/to/ssl/example.com.key;
    return 444;
}