我的虚拟主机配置文件看起来像这样
<VirtualHost *:443>
ServerName api.example.com
DocumentRoot /var/www/example.com/live/api/
<Directory /var/www/example.com/live/api/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mycert.pem
SSLCertificateKeyFile /etc/ssl/private/mycert.key
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/live/
<Directory /var/www/example.com/live/>
Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error-example.com-live.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
一旦我尝试访问https://api.example.com,我就会被重定向到http://www.example.com。当我将文档根更改为 /var/www/whatever-but-not-used-by-other-vhost 时,它可以正常工作。
谢谢你的帮助