【发布时间】:2015-12-18 17:52:00
【问题描述】:
在此示例中,域已替换为 domain.com
我们的主要问题: 当我输入https://domain.com 时,我没有被重定向到https://www.domain.com,我们目前对此没有规定什么是解决这个问题的最佳方法?
根据我们的 nginx 配置,我们没有为 https://domain.com 指定 443 但仍然可以访问,这是为什么呢?
我们拥有适用于 domain.com 和 www.domain.com 的有效 ssl 证书。 我们没有通配符证书 *.domain.com。
我们的配置:
#All non-matching patterns
server
{
listen 80;
#enabling this will cause things to break.
#2015/12/18 09:21:54 [error] 32165#0: *1661 no "ssl_certificate" is defined in server listening on SSL port while SSL handshaking, client: *censored*, server: 0.0.0.0:443
#listen 443 ssl;
#Horrible looking match all pattern.
server_name _ "" domain.com *.domain.com;
return 301 https://www.domain.com$request_uri;
}
#Main site ssl enforced
server
{
listen 443 ssl;
server_name www.domain.com ios.domain.com android.domain.com;
...
}
#Staging / Test site
server
{
listen 443 ssl;
listen 80;
server_name stage.domain.com;
...
}
#Rental cars site ssl enforced
server
{
listen 443 ssl;
server_name hyrbil.domain.com;
...
}
#ios redirect to enforce https
server
{
listen 80;
server_name ios.domain.com;
return 301 https://ios.domain.com$request_uri;
}
#android redirect to enforce https
server
{
listen 80;
server_name android.domain.com;
return 301 https://android.domain.com$request_uri;
}
奖金问题: 是否可以匹配所有 ssl 流量并进行重定向,除非它与特定域匹配,例如让 https://xxx.domain.com 将 301 传递给 https://www.domain.com,即使我没有 xxx.domain.com 的证书而不显示“此页面不安全,您确定要继续吗?
【问题讨论】:
-
nginx 总是选择一个响应请求的服务器。如果它无法匹配
server_name,它将为port选择默认(通常是第一个)服务器块。
标签: nginx