您的位置:首页 > 运维架构 > Apache

Apache默认虚拟主机

2015-12-29 00:17 429 查看
之前我们配置了两个域名:test和aaa,或者访问IP的时候也能跳转到discuz论坛,这有一个概念叫做默认的虚拟主机配置文件,不管是哪一个域名只要是你解析过来都能解析到该论坛,举个列子:比如我们打开计算机-C盘-windows-systmes32-drivers-etc-hosts用写字板打开
加入:192.168.140.100 www.test.com www.aaa.com www.222.com
它也能解析到192.168.140.100这个discuz论坛里面去,ping www.222.com也是到这个192.168.140.100
结论是不管你是什么域名,只要你把它指向到这台服务器,那么它都会访问到这个网站,那这个网站是什么呢,是我们虚拟主机里面的第一个配置文件里边的网站,这个时候我们如果想要限制的话,比如说222.com 它本来不是我的域名解析过来之后也能访问我的网站,这是不符合规范的不安全,所以我们给它做一个限制,我们就把第一个站点直接拒绝掉
[root@zhangmengjunlinux ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/tmp/123" 这个目录不存在
ServerName 111.com 随便写
</VirtualHost> 是这一个配置文件里的网站
<VirtualHost *:80>
DocumentRoot "/data/www/"
ServerName www.test.com
ServerAlias www.aaa.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory /data/www/abc>
AllowOverride AuthConfig
AuthName "aaa"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>
</VirtualHost>
[root@zhangmengjunlinux ~]# ls /tmp/123
ls: 无法访问/tmp/123: 没有那个文件或目录
[root@zhangmengjunlinux ~]# apachectl -t
Warning: DocumentRoot [/tmp/123] does not exist
Syntax error on line 28 of /usr/local/apache2/conf/extra/httpd-vhosts.conf:
Invalid command 'SeverName', perhaps misspelled or defined by a module not included in the server configuration
[root@zhangmengjunlinux ~]# mkdir /tmp/123
[root@zhangmengjunlinux ~]# chmod 600 /tmp/123
[root@zhangmengjunlinux ~]# ls -al /tmp/123
总用量 8
drw------- 2 root root 4096 12月 27 23:53 .
drwxrwxrwt. 5 root root 4096 12月 27 23:53 ..
[root@zhangmengjunlinux ~]# apachectl -t
Syntax error on line 28 of /usr/local/apache2/conf/extra/httpd-vhosts.conf:
Invalid command 'SeverName', perhaps misspelled or defined by a module not included in the server configuration
[root@zhangmengjunlinux ~]# !vim
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
[root@zhangmengjunlinux ~]# apachectl -t
Syntax OK
所以说apache它的默认虚拟主机就是第一个,你想把它禁掉很简单

创建一个空目录就可以了,里面什么都不要加

域名随便写一个
这是怎样去禁掉默认的虚拟主机

本文出自 “田埂上的梦” 博客,请务必保留此出处http://mengjunlinux.blog.51cto.com/10772888/1729372
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: