如何在没有 SSL 证书的情况下运行虚拟主机 443?

Que*_*low 3 ssl https mod-ssl openssl apache-2.2

我有一个 virtualhost 指令,如果输入无效的子域,它会提供自定义 404 错误:

<VirtualHost *:80> # the first virtual host
  ServerName site_not_found
  RedirectMatch 404 ^/(?!custom_error)
</VirtualHost>

<VirtualHost *:80>
  ServerName example.com
  ServerAlias ??.example.com
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我想设置一个虚拟主机以通过 HTTPS 连接显示相同的自定义错误。我尝试了以下方法:

<VirtualHost *:443> # the first virtual host
  ServerName site_not_found
  RedirectMatch 404 ^/(?!custom_error)
</VirtualHost>

<VirtualHost *:443>
  ServerName example.com
  ServerAlias ??.example.com
# SSL options, other options, and stuff defined here.
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

但是服务器不会启动并发出错误:

服务器应该是 SSL-aware 但没有配置证书 [提示:SSLCertificateFile] ((null):0)

即使没有为这个虚拟主机打开 SSLEngine,似乎也需要 SSL 证书。除了提供证书之外,还有没有办法解决这个问题?关闭模块不是一个选项,因为我需要为虚拟服务器 example.com 使用 SSL。

Jay*_*Jay 5

即使没有为这个虚拟主机打开 SSLEngine,似乎也需要 SSL 证书。除了提供证书之外,还有没有办法解决这个问题?

否 - 当您的浏览器包含https在 URL 中时,它希望使用 SSL。它不会,它会失败。Apache 告诉您这一点很好,否则您将有一些难以理解的浏览器错误。因此,您需要先在 Apache 中配置 SSL,然后才能使用 port 443

如果您不希望浏览器警告它是错误的 SSL 证书,则需要从证书颁发机构购买一个。您可以https://cert.startcom.org/获得一个免费的,它在越来越多的地方被接受,但可能没有与付费版本相同的认可水平(尤其是在旧机器中)。我将它用于我的开发站点,但还没有看到有关它们不受信任的警告,但我再次只使用相对较新的操作系统/浏览器。