Apache--虚似机配置

 
1, 基于 IP 虚拟主机
 a, 基于端口
[root@localhost httpd]#  echo “Include vhost/vhost.conf”>>[U1] /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> [U2] 
 DocumentRoot /var/www/vhost88 [U3] 
 ServerName 192.168.1.7:88 [U4] 
 CustomLog /var/www/vhost88/access_log combined[U5] 
</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
 
 
 [U1] 这是双 >
 [U2] IP 和端口号
 [U3] 页面存目录
 [U4] 主机名
 [U5] 访问日志目录

本文出自 “0℃/IT” 博客,转载请与作者联系!

你可能感兴趣的:(linux,职场,休闲)