添加虚拟主机后Apache无法启动

时间:2019-08-22 07:14:30

标签: apache virtualhost httpd.conf

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

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

,而且我也按照类似线程中的建议从https.conf中取消了Include conf/extra/httpd-vhosts.conf的注释。 我还在127.0.0.1 basicwebsite.dev中添加了windows/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

当我从httpd-vhosts.conf删除VirtualHost时,Apache再次开始正常运行。

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

2 个答案:

答案 0 :(得分:0)

步骤1:

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

虚拟主机

#Include 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,保存文件。

Step3:

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

在文件末尾添加以下行。

127.0.0.1      <SERVER_NAME like local.pos.com>

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

这就是设置虚拟主机所需的全部内容。

答案 1 :(得分:0)

尝试在您的VirtualHost中添加Directory标记

<VirtualHost *:80>
    ServerAdmin webmaster@localhost.com
    DocumentRoot "C:/xampp/htdocs/basicwebsite/public"
    ServerName basicwebsite.dev
    <Directory "C:/xampp/htdocs/basicwebsite/public">
    Order allow,deny
    Allow from all
    </Directory>
</VirtualHost>