最后我将 apache2 设置为为所有子域名获取单一证书。
[...]
# Go ahead and accept connections for these vhosts
# from non-SNI clients
SSLStrictSNIVHostCheck off
# Apache setup which will listen for and accept SSL connections on port 443.
Listen 443
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:443
# Because this virtual host is defined first, it will
# be used as the default if the hostname is not received
# in the SSL handshake, e.g. if the browser doesn't support
# SNI.
<VirtualHost *:443>
ServerName domain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/domain/public"
<Directory "/Users/<my_user_name>/Sites/domain/public">
Order allow,deny
Allow from all
</Directory>
# SSL Configuration
SSLEngine on
...
</VirtualHost>
<VirtualHost *:443>
ServerName subdomain1.domain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/subdomain1/public"
<Directory "/Users/<my_user_name>/Sites/subdomain1/public">
Order allow,deny
Allow from all
</Directory>
# SSL Configuration
SSLEngine on
...
</VirtualHost>
<VirtualHost *:443>
ServerName subdomain2.domain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/subdomain2/public"
<Directory "/Users/<my_user_name>/Sites/subdomain2/public">
Order allow,deny
Allow from all
</Directory>
# SSL Configuration
SSLEngine on
...
</VirtualHost>
例如,我可以正确访问
https://subdomain1.domain.localhost
https://subdomain2.domain.localhost
...
无论如何,现在我无法访问
http://subdomain1.domain.localhost
http://subdomain2.domain.localhost
...
由于我使用 Mac Os,因此在访问“http:版本”时,我得到一个默认页面“你的网页。“(而不是错误)。为什么会发生这种情况?
编辑:部分解决B-\
在“httpd配置文件' 此代码适用于该域的所有子域(例如'域名.本地主机'):
<VirtualHost *:80>
ServerName domain.localhost
DocumentRoot "/Users/<my_user_name>/Sites/domain/public"
<Directory "/Users/<my_user_name>/Sites/domain/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
现在当我尝试访问http://subdomain1.domain.localhost
或 时http://subdomain2.domain.localhost
,浏览器会自动将我重定向到http://domain.localhost
。为什么?如何解决?
答案1
<VirtualHost *:80>
现在为每个子域添加编辑的部分:
<VirtualHost *:80>
ServerName subdomain1.domain.localhost
...
<VirtualHost *:80>
ServerName subdomain2.domain.localhost
...
答案2
您必须为所有 http 虚拟主机单独定义。因此,对于每个 https,都有一个匹配的 http。