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