ssl - 为什么 listen `443 default_server ssl` 对 nginx 中的多个服务器名称起作用?

标签 ssl nginx

我为静态内容运行 nginx,并作为 Apache/mod_wsgi 服务 django 的代理。我有 example.com 和 test.example.com 作为 Apache/Django 和 static.example.com 的代理,它直接通过 nginx 提供所有静态文件。我有一个通配符 SSL 证书,这样每个子域都可以使用 SSL(而我只有一个 IP)。

为什么在 test.example.com example.com 中使用 listen 443 default_server ssl; 时,SSL 适用于两者我都必须明确地听取 static.example.com 的 443?

ssl_certificate         /etc/ssl/certs/example.chained.crt;
ssl_certificate_key     /etc/ssl/private/example.key;

server {
    listen      80;
    listen      443;
    server_name static.example.com;
    # ... serves content ...
}

server {
    listen       80;
    listen      443 default_server ssl;
    server_name  example.com;
    # ... proxy pass to http://example.com:8080 (apache) ...
}
server {
    listen      80;
    # why don't I need `listen 443;` here?
    server_name test.example.com;
    # ... proxy pass to http://test.example.com:8080 (apache) ...
}

最佳答案

SSL 协议(protocol)本身(没有 SNI 扩展名)使用服务器的 IP 地址来请求 SSL 证书。对于 SNI,它还会传递主机名(不适用于 Win XP),但这与此处无关。

服务器指令不完全匹配。这是“最接近”的匹配。它可能看起来“有效”,但它可能以错误的服务器指令结束。如果没有更多信息(例如服务器根目录),很难判断。

重点是某些东西总是有效的,因为您似乎使用的是单个 IP 地址。

关于ssl - 为什么 listen `443 default_server ssl` 对 nginx 中的多个服务器名称起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7422349/

相关文章:

apache - 使用 https 将公园域重定向到 http

ssl - 哪个浏览器正在使用 openssl

python-3.x - CERTIFICATE_VERIFY_FAILED Python 3.6 mac osx 无法修复 'Install Certificates.command'

NGINX 配置 :

docker - jwilder/nginx-proxy 和 jrcs/letsencrypt-nginx-proxy-companion 后面的 docker 中的 gitea

nginx - 用于实时流媒体的 MPEG-DASH 编码

spring - 在 Tomcat 和 Spring 中使用 SSL

encryption - 在 ssl 之上的应用层加密数据

angularjs - 如何使用nginx来提高nodejs的性能

bash - consul-template 在模板中使用地址而不是服务地址