当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > 基于IP,port和域名三种虚拟主机配置方法

Linux服务器
linux轻量级 Web 服务器
apache的多站点虚拟主机配置方法
linux服务器后台设置小技巧
.htaccess设置指南经典说明
Apache中利用mod_rewrite实现防盗链
CentOS Linux 下配置Apache2+PHP5+MySQL5+GD库的方法
实现两台MySQL数据库数据的同步的方法
安全检测Unix和Linux服务器安全设置入门精讲
比较详细的基于CentOS的WWW服务器架设指南
科普Solaris系统安全常用命令小结
Linux ls命令参数详解
Linux tar命令使用列子
Linux 下rpm命令参数详解
linux cat more less显示文件的区别
linux下/etc/passwd文件的选项说明
linux .htaccess 设置 404 等错误页面
.htaccess教程之.httacces文件介绍与创建
.httacces文件的配置技巧
.httacces文件的密码保护和防止盗链的实现方法
.htaccess文件使用教程总结

Linux服务器 中的 基于IP,port和域名三种虚拟主机配置方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-18   浏览: 76 ::
收藏到网摘: n/a


1.基于相同IP不同Port的虚拟主机

1)vi/etc/http/conf/httpd.conf

2)将Listen字段改为
Listen80
Listen8888
(以上设置表示使用80以及8888端口)

3)更改虚拟主机部分为:
<VirtualHost192.168.0.1:80>
DocumentRoot/var/www/html/website1
</VirtualHost>
<VirtualHost192.168.0.1:8888>
DocumentRoot/var/www/html/website2
</VirtualHost>

4)保存以上设置

5)创建目录以及页面文件:
#mkdir–p/var/www/html/website1
#mkdir–p/var/www/html/website2
#cd/var/www/html/website1
#cat>index.html<<EOF
>website1
>EOF
#cd/var/www/html/website2
#cat>index.html<<EOF
>website2
>EOF

(注:在/etc/httpd/conf/httpd.conf中有DirectoryIndexindex.htmlindex.html.var,表示只读index.html,而不读index.htm,切记)

6)servicehttpdrestart

完成以上设置后,可以通过以下方式访问:

1)打开浏览器

2)输入http://192.168.0.1:80以及http://192.168.0.1:8888

2.基于相同Port不同IP的虚拟主机

1)不同IP地址的配置:
#cd/etc/sysconfig/network-scripts
#cpifcfg-eth0ifcfg-eth0:1
#viifcfg-eth0:1
将eth0:1更改为:
DEVICE=eth0:1
ONBOOT=YES
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0

2)servicenetworkrestart

3)vi/etc/httpd/conf/httpd.conf

4)更改虚拟主机部分为:
<VirtualHost192.168.0.1:80>
DocumentRoot/var/www/html/website1
</VirtualHost>
<VirtualHost192.168.0.2:80>
DocumentRoot/var/www/html/website2
</VirtualHost>

5)创建目录以及页面文件:
#mkdir–p/var/www/html/website1
#mkdir–p/var/www/html/website2
#cd/var/www/html/website1
#cat>index.html<<EOF
>website1
>EOF
#cd/var/www/html/website2
#cat>index.html<<EOF
>website2
>EOF

完成以上设置后,可以通过以下方式访问:

1)打开浏览器

2)输入http://192.168.0.1:80以及http://192.168.0.2:80

3.基于域名的虚拟主机的访问

1)vi/etc/http/conf/httpd.conf

2)更改虚拟主机部分为:
NameVirtualHost192.168.0.1
<VirtualHostwww1.example.com>
DocumentRoot/var/www/html/website1
ServerNamewww1.example.com
</VirtualHost>
<VirtualHostwww2.example.com>
DocumentRoot/var/www/html/website2
ServerNamewww2.example.com
</VirtualHost>

(注:以上设置中NameVirtualHost不可以省略)

3)创建目录以及页面文件:
#mkdir–p/var/www/html/website1
#mkdir–p/var/www/html/website2
#cd/var/www/html/website1
#cat>index.html<<EOF
>website1
>EOF
#cd/var/www/html/website2
#cat>index.html<<EOF
>website2
>EOF

4)完成以上设置后,可以通过以下方式访问:

1)打开浏览器

2)输入http://www1.example.com以及http://www2.example.com