apache配置本地服务器和域名

局域网访问  Require local  --〉  Require all granted

在服务器上面配置Apache多个网站
测试IP:192.168.1.2 (其他IP自己改) 
网站根目录:D:/webroot/ 
网站根目录下的三个网站文件夹名:web001,web002,web003 
测试主页:index.html 里面的内容自己写,最好内容不同,以测试可以看到 
我在本机测试,假设我有三个域名,www.web01.com,www.web02.com,www.web03.com 
在测试之后,我要改一下系统文件:C:/WINDOWS/system32/drivers/etc下hosts文件 
原来是: 
192.168.1.2 localhost 
再加三行: 
192.168.1.2 localhost 
192.168.1.2 www.web01.com 
192.168.1.2 www.web02.com 
192.168.1.2 www.web03.com 
上面这样,就可以让三个域名的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.com 
DirectoryIndex index.html 
</virtualHost> 
<VirtualHost 192.168.1.2:80> 
DocumentRoot D:/webroot/web002 
ServerName www.web02.com 
DirectoryIndex index.html 
</virtualHost> 
<VirtualHost 192.168.1.2:80> 
DocumentRoot D:/webroot/web003 
ServerName www.web03.com 
DirectoryIndex index.html 
</virtualHost> 
重启APACHE后,就可以用上面的三个域名打开,就会显示不同的内容了,测试成功。 
我们继续扩展上面的代码,以第一个为例: 
NameVirtualHost 192.168.1.2:80 
<VirtualHost 192.168.1.2:80> 
ServerName www.web01.com 
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"
ServerName exp1.xx.com
<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"
ServerName exp2.xx.com
<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 不加会造成网站打开 exp1.xx.com和 exp2.xx.com显示为站点都相同

 

 

 


<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.com
DirectoryIndex index.html index.htm index.php default.php
</VirtualHost>


#Include conf/extra/httpd-vhosts.conf 前面的#去掉,再去编辑httpd-vhosts.conf。

httpd.conf 里面一般放置通用设置。

<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> 
    ServerName www.test.com 
</VirtualHost>


apache 如何配置多站点详细
APACHE多站点配置方法
例如你的主机IP:192.168.1.8
而你有三个站点 www.379life.com www.hlwh.net www.duweng.com

相应的网站文件放在主机的:/website/111;D:/website/222;D:/website/333文件夹下
现在打开APACHE配置文件httpd.conf文件,设置不同的域名到不同的目录中:

NameVirtualHost 192.168.1.8
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/111"
ServerName www.379life.com
</Virtualhost>
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/222"
ServerName www.hlwh.net
</Virtualhost>
<VirtualHost 192.168.1.8>
DocumentRoot "D:/website/333"
ServerName www.duweng.com
</Virtualhost>
保存关闭文件,重启一下APACHE就可以了!

转载于:https://my.oschina.net/PHPDOTAER/blog/112935

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值