您当前的位置: 首页 > 学无止境 > 网站建设 网站首页网站建设
用apache配置服务器虚拟主机
发布时间:2015-10-22 08:53:50编辑:雪饮阅读()
首先需要包含httpd-vhosts配置文件
Vhost中配置虚拟主机
<VirtualHost 127.0.0.1:80>
DocumentRoot "d:/myblog"
#这里配置欢迎首页面
DirectoryIndex index.html index.htm index.php
<Directory>
Options FollowSymLinks
#不许可别人修改我们的页面
AllowOverride None
#设置访问权限
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
这样的配置理论上在apache2.2上面是生效的,但雪饮个人博客亲测在apache2.2.25上面是不生效的,经过一番探索发现如下两种配置方案是生效的:
首先hosts文件中解析如下:
方案一:
<VirtualHost www.xybk.com:80>
DocumentRoot "d:/myblog"
#这里配置欢迎首页面
DirectoryIndex index.html index.htm index.php Untitled-2.html
<Directory "d:/myblog">
Options FollowSymLinks
#不许可别人修改我们的页面
AllowOverride None
#设置访问权限
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
方案二:
<VirtualHost 192.168.0.131:80>
DocumentRoot "d:/myblog"
#这里配置欢迎首页面
DirectoryIndex index.html index.htm index.php Untitled-2.html
<Directory "d:/myblog">
Options FollowSymLinks
#不许可别人修改我们的页面
AllowOverride None
#设置访问权限
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
方案二区别于方案一的就是用ip地址直接绑定
当然也可以参考vhost中默认的主机配置案例如下:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.somenet.com
DocumentRoot "C:/myenv/apache/docs/dummy-host2.somenet.com"
ServerName dummy-host2.somenet.com
ErrorLog "logs/dummy-host2.somenet.com-error.log"
CustomLog "logs/dummy-host2.somenet.com-access.log" common
</VirtualHost>
关键字词:apache,虚拟主机,个人博客