1,
基于
IP
虚拟主机
a,
基于端口
[root@localhost httpd]#
echo “Include vhost/vhost.conf”>>/etc/httpd/conf/httpd.conf
[root@localhost httpd]#
mkdir /etc/httpd/vhost
(在
httpd
目录下新建目录
vhost
)
[root@localhost httpd]#
vim vhost/vhost.conf (
配置文件
)
<VirtualHost 192.168.1.7:88>
DocumentRoot /var/www/vhost88
ServerName 192.168.1.7:88
CustomLog /var/www/vhost88/access_log combined
</VirtualHost>
[root@localhost httpd]#
mkdir /var/www/vhost88
[root@localhost httpd]#
echo "vhost88">/var/www/vhost88/vhost.html
[root@localhost httpd]#
/etc/in.it/httpd restart
2,
基于名称虚似主机
Vim /etc/hosts
设置
IP
对应主机名
[root@localhos thttpd]#
echo "Include name/name.conf">>/etc/httpd/conf/httpd.conf
[root@localhost httpd]# mkdir name
[root@localhost httpd]# vim name.conf
NameVirtualHost 192.168.1.7
<VirtualHost [url]www.abc.com.cn>[/url]
DocumentRoot /var/www/abc
serverName [url]www.abc.con.cn[/url]
CustomLog /var/www/abc/access_log combined
</virtualHost>
<VirtualHost [url]www.def.com.cn>[/url]
DocumentRoot /var/www/def
serverName [url]www.def.con.cn[/url]
CustomLog /var/www/abc/access_log combined
</virtualHost>
[root@localhost ~]# mkdir /var/www/abc
[root@localhost ~]# mkdir /var/www/def
[root@localhost ~]# echo "abc">/var/www/abc/index.html
[root@localhost ~]# echo "def">/var/www/def/index.html
[root@localhost ~]#/etc/rc.d/init.d/httpd restart
本文出自 “0℃/IT” 博客,转载请与作者联系!