【问题标题】:Nginx redirect root domain which is not in SSL certificateNginx 重定向不在 SSL 证书中的根域
【发布时间】:2015-11-20 09:03:09
【问题描述】:

我有一个*.example.com 的 SSL 通配符证书,它对根域无效。我希望 Ubuntu 14.04 上的 Nginx 到

  1. 只接受对已定义主机的请求
  2. 将根域和www子域的所有http请求重定向到https www子域
  3. 仅在端口 443 上为根域返回 404,例如如果请求是 https://example.com

通过复制下面的配置,我设法实现了 1 和 2。

server {
    #listen 80;
    #isten 443;
   return 404;
}

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

server {

    listen 443 ssl;
    #certificate and key referenced in common.conf
    server_name www.example.com;

    root /usr/share/nginx/html/example.com;
    index index.php index.html index.htm;

    include common/common.conf;
}

当我从上面的第二行和第三行中删除注释标记时,希望仅为 https://example.com 返回 404 - 没有任何效果。例如,我在 Chrome 中得到了 https://www.example.com/http://ww.example.com/ 的 ERR_CONNECTION_CLOSED。

我应该怎么做才能同时实现 1)、2) 和 3)?

非常感谢。

【问题讨论】:

    标签: redirect ssl nginx


    【解决方案1】:

    ... *.example.com 的通配符证书对根域无效 ...仅在端口 443 上为根域返回 404,例如如果请求是https://example.com

    这是不可能的。使用 https,HTTP 响应是在为 URL 中的主机建立的 TLS 连接内生成的。因此,要返回 404 以访问 https://example.com,您必须首先拥有经过验证的 TLS 连接。但是因为 example.com 不包含在您的证书中,您在尝试建立 TLS 连接时会收到验证错误,因此没有成功建立 TLS 连接,并且连接内无法返回 404。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2013-11-15
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      相关资源
      最近更新 更多