Apache-2.2
MAMP - 主機名更改為具有兩個 localhost 的項目的第一個 vhost SSL 條目
我有兩個項目在我的 Mac 上使用 MAMP 相互複製。它們都有 SSL 頁面。但是,每當我點擊項目 2 的安全 SSL 頁面時,base_url 或主機都會更改為 project1 而不是剩餘的 project2。我知道這是虛擬主機的問題,因為如果我切換條目的順序,則會發生相反的情況。這是我的配置文件:
/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
更改
<VirtualHost _default_:443>
到
<VirtualHost *:443>
然後確保你有
NameVirtualHost *:443
然後重新啟動apache,它應該可以工作
編輯
你也不需要 443 in
ServerName proj1.localhost:443
這是因為主機名是加密發送的,SSL 解密發生在虛擬主機內部,而不是外部。這意味著伺服器在選擇虛擬主機時無權訪問主機名,因此它將始終選擇第一個。您可以在wiki.apache.org上閱讀更多相關資訊