直接看代码吧:
普通虚拟主机: 详细:http://lamp.linux.gov.cn/Apache/ApacheMenu/vhosts/examples.html
NameVirtualHost *:80
<VirtualHost *:80>
ServerName upall.local
ServerAlias localhost 192.168.1.45
ServerAdmin 800@upall.cn
DocumentRoot "D:/WebSite/www"
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
动态虚拟主机: 详细:http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_vhost_alias.html
说明:需要启用“mod_vhost_alias”模块
# 从 Host: 头中取得服务器名字 Server Name UseCanonicalName Off # 这里的日志格式,可以在将来通过第一个参数域来分隔不同的虚拟主机的日志 LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon CustomLog logs/access_log vcommon # 在返回请求的文件名的路径中包含进服务器名字: server name VirtualDocumentRoot /www/hosts/%0/docs VirtualScriptAlias /www/hosts/%0/cgi-bin
既有普通虚拟主机又有动态虚拟主机:
UseCanonicalName off
VirtualDocumentRoot D:/wamp/demo/%0
<VirtualHost *:80>
ServerName upall.local
ServerAlias localhost 192.168.1.45
ServerAdmin 800@upall.cn
#DocumentRoot "D:/WebSite/www"
# 上边这句要换成下边的:
VirtualDocumentRoot "D:/WebSite/upall.local"
# 或者下边:
#VirtualDocumentRoot "D:/WebSite/%0"
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<完>