Apache 2.2 伺服器在新增虛擬網域代碼後停止

Apache 2.2 伺服器在新增虛擬網域代碼後停止

我正在 Apache 2.2 本地伺服器上開發一個網站。該網站仍處於開發階段。我想為我的網站取得一個自訂域名,以便我可以將其作為“mysite.local”或其他內容而不是“localhost/xyz.php”進行存取。經過對 google 的足夠研究後,我將這些行添加到 httpd.conf 檔案中:

NameVirtualHost 127.0.0.1  
<VirtualHost 127.0.0.1>  
    DocumentRoot “C:/Apache/htdocs"  
    ServerName localhost  
</VirtualHost>  
<VirtualHost 127.0.0.1>  
    ServerName the-mini-project.com  
    ServerAlias the-mini-project.com  
    DocumentRoot “C:/Apache/htdocs”  
</VirtualHost>

我還將該行添加127.0.0.1 the-mini-project.com到主機文件中。這些行的語法有問題還是其他問題?因為在我添加這些行後伺服器停止運行。當我把它們去掉後就恢復正常了。請幫忙。還有其他建議嗎?謝謝。

日誌/錯誤.txt

[Fri Aug 30 19:56:12 2013] [notice] Child 6676: Child process is exiting  
[Fri Aug 30 19:56:12 2013] [notice] Parent: Child process exited successfully.  
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.100 for ServerName  
[Fri Aug 30 19:56:20 2013] [notice] Apache/2.2.25 (Win32) PHP/5.3.27 configured -- resuming normal operations  
[Fri Aug 30 19:56:20 2013] [notice] Server built: Jul 10 2013 01:52:12  
[Fri Aug 30 19:56:20 2013] [notice] Parent: Created child process 3152    
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.100 for ServerName  
httpd.exe: Could not reliably determine the server's fully qualified domain name, using 192.168.1.100 for ServerName  

答案1

這個配置沒有任何意義。日誌可能會或可能不會告訴您出了什麼問題,但我想這是您真正想要的:

NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
    DocumentRoot "C:/Apache/htdocs"
    ServerName localhost
    ServerAlias the-mini-project.com
</VirtualHost>

https://httpd.apache.org/docs/2.2/mod/core.html#virtualhost

答案2

只是一個小錯誤。連接埠號碼遺失。我自己想出來了。為了供日後參考,正確的方法是:

NameVirtualHost 127.0.0.1:80
"<"VirtualHost 127.0.0.1:80">"
DocumentRoot "C:/Apache/htdocs"
ServerName localhost
"<"/VirtualHost">"
"<"VirtualualHost">127.0
. yoursite.anything
ServerAlias yoursite.anything
DocumentRoot “C:/Apache/htdocs”
“<”/VirtualHost">”

80 是預設連接埠號碼。

相關內容