Apache多站点配置及启动失败解决办法

时间:2023-12-14 13:48:02

一、 Apache多站点配置方法

1、打开Apache安装目录下conf/httpd.conf文件,找到下面两行文字,把最前面的 # 号去掉,然后保存。

#LoadModule vhost_alias_module modules/mod_vhost_alias.so

#Include conf/extra/httpd-vhosts.conf

2、接着找到同一文件中的DocumentRoot和Directory,改为站点目录的上一级目录

例如站点放在 C:/XAMPP/Appserv/Web/htdocs/,则改为以下形式

A、DocumentRoot "C:/XAMPP/Appserv/Web";

B、<Directory "C:/XAMPP/Appserv/Web">;

后续各个应用可部署在此目录下。

3、上述配置完成后即可打开Apache安装目录下/conf/extra/httpd-vhosts.conf文件,在最后添加如下:

<VirtualHost *:3333>
DocumentRoot "C:/xampp/Appserv/Webhtdocs"
ServerName localhost:3333
ErrorLog "logs/localhost3333-error.log"
</VirtualHost>
<VirtualHost *:3334>
DocumentRoot "C:/xampp/Appserv/Webmall"
ServerName localhost:3334
ErrorLog "logs/Slocalhost3334-error.log"
</VirtualHost>

至此,多站点配置工作完毕。

我在配置完后,由于上述第3步的配置有问题,导致Apache服务无法启动,在Apache的Log及Windows的日志内都无法找到具体的具体的错误信息提示。

以下是我用Xampp启动Apache时的错误:

8:42:47 [main] Initializing Control Panel
8:42:47 [main] Windows Version: Windows 7 Professional 32-bit
8:42:47 [main] XAMPP Version: 1.8.3
8:42:47 [main] Control Panel Version: 3.2.1 [ Compiled: May 7th 2013 ]
8:42:47 [main] You are not running with administrator rights! This will work for
8:42:47 [main] most application stuff but whenever you do something with services
8:42:47 [main] there will be a security dialogue or things will break! So think
8:42:47 [main] about running this application with administrator rights!
8:42:47 [main] XAMPP Installation Directory: "c:\xampp\"
8:42:47 [main] Checking for prerequisites
8:42:47 [main] All prerequisites found
8:42:47 [main] Initializing Modules
8:42:47 [main] Starting Check-Timer
8:42:47 [main] Control Panel Ready
8:43:06 [Apache] Attempting to start Apache app...
8:43:06 [Apache] Status change detected: running
8:43:07 [Apache] Status change detected: stopped
8:43:07 [Apache] Error: Apache shutdown unexpectedly.
8:43:07 [Apache] This may be due to a blocked port, missing dependencies,
8:43:07 [Apache] improper privileges, a crash, or a shutdown by another method.
8:43:07 [Apache] Press the Logs button to view error logs and check
8:43:07 [Apache] the Windows Event Viewer for more clues
8:43:07 [Apache] If you need more help, copy and post this
8:43:07 [Apache] entire log window on the forums

上述错误,在度娘提供的帮助中,大都是说端口被占用,其实并不准确,最简单的办法,就是直接在CMD命令框内执行httpd.exe,此时命令框会提示具体的出错原因:

Apache多站点配置及启动失败解决办法

按上述提示直接解决。