Apache默認虛擬主機

    以前咱們配置了兩個域名:test和aaa,或者訪問IP的時候也能跳轉到discuz論壇,這有一個概念叫作默認的虛擬主機配置文件,無論是哪個域名只要是你解析過來都能解析到該論壇,舉個列子:好比咱們打開計算機-C盤-windows-systmes32-drivers-etc-hosts用寫字板打開       linux

     加入:192.168.140.100  www.test.com   www.aaa.com  www.222.com apache

它也能解析到192.168.140.100這個discuz論壇裏面去,ping www.222.com也是到這個192.168.140.100 vim

結論是無論你是什麼域名,只要你把它指向到這臺服務器,那麼它都會訪問到這個網站,那這個網站是什麼呢,是咱們虛擬主機裏面的第一個配置文件裏邊的網站,這個時候咱們若是想要限制的話,好比說222.com 它原本不是個人域名解析過來以後也能訪問個人網站,這是不符合規範的不安全,因此咱們給它作一個限制,咱們就把第一個站點直接拒絕掉windows

[root@zhangmengjunlinux ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 安全

<VirtualHost *:80>       服務器

   DocumentRoot "/tmp/123"     這個目錄不存在ide

   ServerName    111.com       隨便寫網站

</VirtualHost>               是這一個配置文件裏的網站ui

<VirtualHost *:80>spa

    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它的默認虛擬主機就是第一個,你想把它禁掉很簡單

  1. 建立一個空目錄就能夠了,裏面什麼都不要加

  2. 域名隨便寫一個

    這是怎樣去禁掉默認的虛擬主機

相關文章
相關標籤/搜索