我在装有 MAMP 的 Mac 上有两个项目,它们互为副本。它们都有 SSL 页面。但是,每当我点击项目 2 的安全 SSL 页面时,base_url 或主机就会更改为 project1,而不是保留 project2。我知道这是 vhosts 的问题,因为如果我切换条目的顺序,就会发生相反的情况。这是我的配置文件:
/Applications/MAMP/conf/extra/httpd-ssl.conf
<VirtualHost _default_:443>
DocumentRoot "/Applications/MAMP/htdocs/proj1"
ServerName proj1.localhost:443
ErrorLog "/Applications/MAMP/Library/logs/error_log"
TransferLog "/Applications/MAMP/Library/logs/access_log"
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/ssl/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/ssl/server.key"
</VirtualHost>
<VirtualHost _default_:443>
DocumentRoot "/Applications/MAMP/htdocs/proj2"
ServerName proj2.localhost:443
ErrorLog "/Applications/MAMP/Library/logs/error_log"
TransferLog "/Applications/MAMP/Library/logs/access_log"
SSLEngine on
SSLCertificateFile "/Applications/MAMP/conf/apache/ssl/server.crt"
SSLCertificateKeyFile "/Applications/MAMP/conf/apache/ssl/server.key"
</VirtualHost>
--------------------
cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 proj1.localhost
127.0.0.1 proj2.localhost
答案1
更改
<VirtualHost _default_:443>
到
<VirtualHost *:443>
然后确保你有
NameVirtualHost *:443
然后重新启动 apache 就可以了
编辑
另外你不需要 443ServerName proj1.localhost:443
答案2
这是因为主机名是加密发送的,SSL 解密发生在虚拟主机内部,而不是外部。这意味着服务器在选择虚拟主机时无法访问主机名,因此它将始终选择第一个。您可以在以下网址阅读更多相关信息维基百科