Apache虚拟主机配置步骤
# 虚拟主机配置指南
#Include conf/extra/httpd-vhosts.conf
取消注释该行,即删除行首的"#"符号,以启用虚拟主机配置文件加载。
2. 修改位于 (Win7) c:/windows/system32/drivers/etc/ 路径下的 hosts 文件。在系统hosts文件中添加一行:127.0.0.1 x.acme.com(替换为你计划使用的测试域名)。
3. 本例使用 WAMP 集成包,配置文件位于 c:/wamp/bin/apache/Apache2.2.11/conf/extra 目录下。编辑配置文件 httpd-vhosts.conf。
NameVirtualHost 指令默认配置如下:
NameVirtualHost *:80
在此基础上增加具体的虚拟主机定义块。
ServerAdmin x@acme.com
DocumentRoot "/var/www/html"
ServerName x.acme.com
ErrorLog "logs/x.acme.com-error.log"
CustomLog "logs/x.acme.com-access.log" common
保存更改后,重启 Apache 服务器服务。
此时在浏览器地址栏输入 http://x.acme.com,即可访问对应的网站目录。
若需在现有 Web 服务器上保留 localhost 访问功能,需额外配置默认主机规则。
在 hosts 文件中追加:127.0.0.1 localhost
同时在 httpd-vhosts.conf 文件中增加针对 localhost 的虚拟主机配置段。
ServerAdmin localhost@xxx.com
DocumentRoot "/var/www/"
ServerName localhost
ErrorLog "logs/ localhost-error.log"
CustomLog "logs/ localhost-access.log" common