使用HTTPS将所有子域重定向到主域,而不使用通配符证书(nginx)

我有一个站点和几个虚拟域名的域名.我希望只能通过HTTPS(使用HSTS)访问所有站点(主站点和虚拟站点),并且我希望将不存在的子站点重定向到主站点.

总结一下我想要的东西:

> https:/example.com:无重定向(主站点)
> http:/example.com:重定向到https:/example.com
> https:/vhost.example.com:无重定向(虚拟主机)
> http:/vhost.example.com:重定向到https:/vhost.example.com
> https:/doesntexist.example.com:重定向到https:/example.com
> http:/doesntexist.example.com:重定向到https:/example.com

我非常接近这一点,但倒数第二次重定向不起作用.我正在使用Let’s Encrypt的证书,该证书目前不提供通配符证书,因此证书仅对主域和vhost(我在创建证书时明确列出)有效.由于证书无效,浏览器会阻止连接.

绕过这个问题最好的方法是什么(如果有的话)?

这是我的(简化)Nginx配置,如果它有帮助:

server {
    listen 80;
    server_name _;
    return 301 https://example.com$request_uri;
}

server {
    listen 443 spdy;
    server_name _;
    # SSL settings snipped for brevity. SPDY and HSTS are enabled.
    return 301 https://example.com$request_uri;
}

server {
    listen 443 spdy;
    server_name example.com;
    root /var/www/example.com;
    index index.html index.htm;
}

server {
    listen 443 spdy;
    server_name vhost.example.com;
    root /var/www/vhost.example.com;
    index index.html index.htm;
}
最佳答案
实际上,如果没有通配符证书,您无法解决问题.如果您无法提供与所请求的名称匹配的证书,那么您将收到连接错误 – 它是协议的基本部分.

我想,从理论上讲,你可以写一些东西,当它收到一个不在证书中的名字的SNI标题时,从Let’s Encrypt快速颁发证书,并在TLS握手中发回新的证书,但是. ..好吧,这不是一个实际的解决方案,是吗?

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...