在服务器上面配置Apache多个网站
测试IP:192.168.1.2 (其他IP自己改)
网站根目录:D:/webroot/
网站根目录下的三个网站文件夹名:web001,web002,web003
测试主页:index.html 里面的内容自己写,最好内容不同,以测试可以看到
我在本机测试,假设我有三个域名,www.web01,www.web02,www.web03
在测试之后,我要改一下系统文件:C:/WINDOWS/system32/drivers/etc下hosts文件
原来是:
192.168.1.2 localhost
再加三行:
192.168.1.2 localhost
192.168.1.2 www.web01
192.168.1.2 www.web02
192.168.1.2 www.web03
上面这样,就可以让三个域名的IP指向到192.168.1.2,满足我们测试的要求。若测试完毕,删除上面三行即可。
下面开始配置多网站:
上面搞好后,那么就可以配置成下面的,记住NameVirtualHost 192.168.1.2:80 这个一定要有,否则,打开所有的域名,都是指向第一个,这个就是很多人出现的配置不成功的问题所在了。
NameVirtualHost 192.168.1.2:80
<VirtualHost 192.168.1.2:80>
DocumentRoot D:/webroot/web001
ServerName www.web01
DirectoryIndex index.html
</virtualHost>
<VirtualHost 192.168.1.2:80>
DocumentRoot D:/webroot/web002
ServerName www.web02
DirectoryIndex index.html
</virtualHost>
<VirtualHost 192.168.1.2:80>
DocumentRoot D:/webroot/web003
ServerName www.web03
DirectoryIndex index.html
</virtualHost>
html主页重启APACHE后,就可以用上面的三个域名打开,就会显示不同的内容了,测试成功。
我们继续扩展上面的代码,以第一个为例:
NameVirtualHost 192.168.1.2:80
<VirtualHost 192.168.1.2:80>
ServerName www.web01
DocumentRoot D:/webroot/web001
DirectoryIndex index.html
<Directory "D:/webroot/web001">
Options Indexes FollowSymLinks
AllowOverride Options FileInfo
order allow,deny
Allow from all
</Directory>
</VirtualHost>
第一个,加入了可以看到根目录所有文件的代码,不过,最好大家不要加上,安全性的问题。
其实扩展的,是在配置文件前面代码基础下,有则覆盖,没则继承的原则来做的,和CSS一样。根据自己的需求来定吧。其他的,大家自己去发现吧。
NameVirtualHost *:85
<VirtualHost *:85>
DocumentRoot "E:/wwwroot/php/we"
<Directory "E:/wwwroot/php/we">   
Options FollowSymLinks IncludesNOEXEC Indexes   
DirectoryIndex  index.php   
AllowOverride None   
Order Deny,Allow   
Allow from all   
</Directory>
</Virtualhost>
<VirtualHost *:85>
DocumentRoot "E:/wwwroot/php/phpadmin/phpadmin"
<Directory "E:/wwwroot/php/phpadmin/phpadmin">   
Options FollowSymLinks IncludesNOEXEC Indexes   
DirectoryIndex  index.php   
AllowOverride None   
Order Deny,Allow   
Allow from all   
</Directory>
</Virtualhost>
全部
都需要 特别是NameVirtualHost *:85 不加会造成网站打开 和 显示为站点都相同
<Directory e:/sp>
Order Deny,Allow
Allow from all
Options All
AllowOverride All
</Directory>
<VirtualHost 127.0.0.2:8080>
DocumentRoot "E:/sp"
ServerName www.c
DirectoryIndex index.html index.htm index.php default.php
</VirtualHost>
#Include conf/f 前面的#去掉,再去编辑f。
<VirtualHost *:80>
ServerAdmin xxxxxxxxxx   
DocumentRoot "xxxxxxxxxxxxx"
<Directory "xxxxxxxxxx">
AddOutputFilterByType DEFLATE text/html text/htm text/shtml text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/xml
</Directory>
st
</VirtualHost>
apache 如何配置多站点详细
APACHE多站点配置方法
例如你的主机IP:192.168.1.8
而你有三个站点 www.379life www.hlwh www.duweng
相应的网站文件放在主机的:/website/111;D:/website/222;D:/website/333文件夹下
现在打开APACHE配置文件f文件,设置不同的域名到不同的目录中:
NameVirtualHost 192.168.1.8
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/111"
ServerName www.379life
</Virtualhost>
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/222"
ServerName www.hlwh
</Virtualhost>
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/333"
ServerName www.duweng
</Virtualhost>
保存关闭文件,重启一下APACHE就可以了!