linux下利用apache的虛擬主機(jī)機(jī)制,沒有綁定的域名或者ip直接訪問時(shí)會(huì)訪問到第一個(gè)虛擬主機(jī)
注:以下操作都需遠(yuǎn)程登錄ssh執(zhí)行命令
centos-默認(rèn)apache:
編輯配置文件
vi /etc/httpd/conf/httpd.conf
在NameVirtualHost *:80下任意添加一個(gè)虛擬主機(jī)配置,如
DocumentRoot "/var/www/html"
ServerName www.baidu.com
deny from all
重啟服務(wù)即可
service httpd restart
centos-wd:
只需刪除一個(gè)文件即可
rm -f /www/web/default/index.php
ubuntu:
vi /etc/apache2/ports.conf
在NameVirtualHost *:80下任意添加一個(gè)虛擬主機(jī)配置,如
DocumentRoot "/var/www/html"
ServerName www.baidu.com
deny from all
重啟服務(wù)即可
/etc/init.d/apache2 restart