![MAMP-具有两个本地主机的项目的主机名更改为第一个 vhost SSL 条目](https://linux22.com/image/598024/MAMP-%E5%85%B7%E6%9C%89%E4%B8%A4%E4%B8%AA%E6%9C%AC%E5%9C%B0%E4%B8%BB%E6%9C%BA%E7%9A%84%E9%A1%B9%E7%9B%AE%E7%9A%84%E4%B8%BB%E6%9C%BA%E5%90%8D%E6%9B%B4%E6%94%B9%E4%B8%BA%E7%AC%AC%E4%B8%80%E4%B8%AA%20vhost%20SSL%20%E6%9D%A1%E7%9B%AE.png)
我在装有 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 解密发生在虚拟主机内部,而不是外部。这意味着服务器在选择虚拟主机时无法访问主机名,因此它将始终选择第一个。您可以在以下网址阅读更多相关信息维基百科