添加虚拟域名代码后 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到 hosts 文件中。这些行的语法有问题吗?还是其他问题?因为在我添加这些行后,服务器停止运行。当我删除它们时,它恢复正常。请帮忙。还有其他建议吗?谢谢。

日志/错误.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

只是一个小错误。端口号丢失了。我自己弄明白了。为了便于参考,正确的做法是:

名称虚拟主机 127.0.0.1:80
"<"虚拟主机 127.0.0.1:80">"
DocumentRoot “C:/Apache/htdocs"
服务器名称本地主机
"<"/虚拟主机">"
"<"虚拟主机 127.0.0.1:80">"
服务器名称yoursite.anything
服务器别名yoursite.anything
DocumentRoot “C:/Apache/htdocs”
"<"/虚拟主机">"

80 是默认端口号。

相关内容