首页 > 解决方案 > 添加虚拟主机后 Apache 未启动

问题描述

我在 httpd-vhosts.conf 中添加了一个虚拟主机如下

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    DocumentRoot "C:/xampp/htdocs/basicwebsite/public"
    ServerName basicwebsite.dev
</VirtualHost>

我也Include conf/extra/httpd-vhosts.conf按照类似线程中的建议取消了对 https.conf 的评论。我还添加127.0.0.1 basicwebsite.devwindows/system32/drivers/etc/hosts.

现在当我启动 Apache 它给出了以下错误

12:07:33 PM  [Apache]   Error: Apache shutdown unexpectedly.
12:07:33 PM  [Apache]   This may be due to a blocked port, missing dependencies, 
12:07:33 PM  [Apache]   improper privileges, a crash, or a shutdown by another method.
12:07:33 PM  [Apache]   Press the Logs button to view error logs and check
12:07:33 PM  [Apache]   the Windows Event Viewer for more clues
12:07:33 PM  [Apache]   If you need more help, copy and post this
12:07:33 PM  [Apache]   entire log window on the forums

当我从 中删除 VirtualHost 时httpd-vhosts.conf,Apache 再次开始顺利工作..

我做错了什么?任何建议/帮助将不胜感激。

标签: apachevirtualhosthttpd.conf

解决方案


步骤1:

打开 C:\xampp\apache\conf\httpd.conf 中存在的 httpd.conf 文件 删除存在的 #(hash) 符号以在 httpd.conf 文件中包含“httpd-vhosts.conf”文件。

虚拟主机

#包括conf/extra/httpd-vhosts.conf

虚拟主机

包括 conf/extra/httpd-vhosts.conf

第2步:

创建一个虚拟主机文件。打开“httpd-vhosts.conf”文件。并复制以下代码行。

<VirtualHost *:80>
  ServerAdmin webmaster@localhost.com
  DocumentRoot <PATH_TO_PROJECT_DIRECTORY_HERE>
  ServerName <SERVER_NAME like local.pos.com>
</VirtualHost>

将 PATH_TO_PROJECT_DIRECTORY_HERE & SERVER_NAME 替换为适当的值,保存文件。

第三步:

打开 C:\Windows\System32\drivers\etc\hosts

在文件末尾添加以下行。

127.0.0.1      <SERVER_NAME like local.pos.com>

重新启动 apache 服务器并访问站点 URL。

这就是设置虚拟主机所需要的一切。


推荐阅读