5534 发表于 2015-12-30 14:15:40

Apache默认虚拟主机

   之前我们配置了两个域名:test和aaa,或者访问IP的时候也能跳转到discuz论坛,这有一个概念叫做默认的虚拟主机配置文件,不管是哪一个域名只要是你解析过来都能解析到该论坛,举个列子:比如我们打开计算机-C盘-windows-systmes32-drivers-etc-hosts用写字板打开      
   加入:192.168.140.100www.test.com   www.aaa.comwww.222.com
它也能解析到192.168.140.100这个discuz论坛里面去,ping www.222.com也是到这个192.168.140.100
结论是不管你是什么域名,只要你把它指向到这台服务器,那么它都会访问到这个网站,那这个网站是什么呢,是我们虚拟主机里面的第一个配置文件里边的网站,这个时候我们如果想要限制的话,比如说222.com 它本来不是我的域名解析过来之后也能访问我的网站,这是不符合规范的不安全,所以我们给它做一个限制,我们就把第一个站点直接拒绝掉
# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>      
   DocumentRoot "/tmp/123"   这个目录不存在
   ServerName    111.com       随便写
</VirtualHost>               是这一个配置文件里的网站
<VirtualHost *:80>
    DocumentRoot "/data/www/"
    ServerNamewww.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>
# ls /tmp/123
ls: 无法访问/tmp/123: 没有那个文件或目录
# apachectl -t
Warning: DocumentRoot 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
# mkdir /tmp/123
# chmod 600 /tmp/123
# ls -al /tmp/123
总用量 8
drw-------2 root root 4096 12月 27 23:53 .
drwxrwxrwt. 5 root root 4096 12月 27 23:53 ..
# 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
# !vim
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
# apachectl -t
Syntax OK
所以说apache它的默认虚拟主机就是第一个,你想把它禁掉很简单


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

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


页: [1]
查看完整版本: Apache默认虚拟主机