我的 Apache 服务器上安装了通配符 SSL。使用下面的代码片段,可以实现以下功能:
http://test.com (points to /var/www/html)
https://test.com (points to /var/www/html)
http://s1.test.com (points to /var/www/s1)
但https://s1.test.com不起作用 - 它指向 /var/www/html 而不是 /var/www/s1 - 我怎样才能让它指向它自己的目录?
<VirtualHost *:443>
DocumentRoot "/var/www/html"
ServerAlias test.com *.test.com
ServerName *.test.com
SSLEngine on
SSLCertificateFile /home/test/STAR_test_com.crt
SSLCertificateKeyFile /home/test/test.key
SSLCertificateChainFile /home/test/PositiveSSL.ca-bundle
</VirtualHost>
<VirtualHost *:443>
ServerAlias s1.test.com *.s1.test.com
ServerName s1.test.com
DocumentRoot "/var/www/s1"
SSLEngine on
SSLCertificateFile /home/test/STAR_test_com.crt
SSLCertificateKeyFile /home/test/test.key
SSLCertificateChainFile /home/test/PositiveSSL.ca-bundle
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName s1.test.com
ServerAlias s1.test.com
DocumentRoot "/var/www/s1/"
</VirtualHost>
<VirtualHost *:80>
ServerName www.test.com
ServerAlias test.com
DocumentRoot "/var/www/html/"
</VirtualHost>
谢谢!
答案1
您还需要NameVirtualHost *:443
。
答案2
可能是来自第一个虚拟主机的通配符记录
ServerAlias test.com *.test.com
还包括 s1.test.com,因此当您请求 s1.test.com 时,将应用第一个配置块。删除通配符或使 s1.test.com 在配置文件中排在第一位。