我使用nginx和ssl通配符证书一样:
/etc/nginx/sites-enabled/example.com
server { listen 443 default_server ssl; server_name 192.168.0.1 example.com; include /etc/nginx/ssl.conf; error_log /var/log/nginx/example.com.error.ssl.log; access_log /var/log/nginx/example.com.access.ssl.log; root /var/www/example.com/; index index.html; location / { alias /var/www/example.com/example.com/; } } server { listen 80; server_name 192.168.0.1 example.com; return 301 https://$server_name$request_uri; }
/etc/nginx/ssl.conf
包含的ssl.conf如下所示:
ssl_certificate /etc/nginx/ssl/example.com/example.com.crt; ssl_certificate_key /etc/nginx/ssl/example.com/example.com.key; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_dhparam /etc/nginx/ssl/example.com/example.com_dhparam.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers 'AES256+EECDH:AES256+EDH'; add_header Strict-Transport-Security "max-age=15768000; includeSubDomains"; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; ssl_stapling on; ssl_stapling_verify on; resolver 8.8.4.4 8.8.8.8 valid=300s; resolver_timeout 10s;
我的子域的服务器块如下所示:
/etc/nginx/sites-enabled/blog.example.com
server { listen 443; server_name blog.example.com; error_log /var/log/nginx/blog.example.com.error.ssl.log; access_log /var/log/nginx/blog.example.com.access.ssl.log; root /var/www/blog.example.com/; index index.html; location / { proxy_pass http://localhost:2368/; proxy_set_header Host $host; proxy_buffering off; autoindex off; } } server { listen 80; server_name blog.example.com; return 301 https://$server_name$request_uri; }
在子域上的https工作正常,但我想知道为什么它的工作,以及为什么blog.example.cominheritanceexample.com的设置,即使ssl.conf不包括在该服务器块。
在nginx文档中找不到有关从default_serverinheritance设置的任何内容。
这只是通配符证书的预期行为?
谢谢!
即使你没有显示主要的nginx.conf我怀疑你的ssl.conf包含在nginxconfiguration的http级别中。
实际上,所有的http级别设置都会inheritance到nginx中的server块。 请参阅http://blog.martinfjordvald.com/2012/08/understanding-the-nginx-configuration-inheritance-model/了解更多关于指令inheritance如何在nginx中工作的信息。
这实际上是根据文档预期的行为:
SSL连接在浏览器发送HTTP请求之前build立,而nginx不知道请求的服务器的名称。 因此,它只能提供默认的服务器证书。
您可以通过使用不同的IP来避免这种情况:
应该记住的是,由于HTTPS协议的限制,虚拟服务器应该监听不同的IP地址,否则第一个服务器的证书将被发给第二个站点。