Apache配置虚拟服务器三种方式
原创一、基于IP
- 假设服务器有一个IP地址为192.168.1.10,使用ifconfig在同一网络接口中eth0上绑定3个IP:
[root@localhost root]# ifconfig eth0:1 192.168.1.11
[root@localhost root]# ifconfig eth0:2 192.168.1.12
[root@localhost root]# ifconfig eth0:3 192.168.1.13
- 修改hosts文件中,添加三个域名,其中一个:
192.168.1.11 www.test1.com
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com
- 为虚拟主机建立网页的根目录,如中。/www在目录下建立test1、test2、test3单独存储的文件夹1.html、2.html、3.html
/www/test1/1.html
/www/test2/2.html
/www/test3/3.html
- 在httpd.conf资料将附在附件中。httpd-vhosts.conf包括、遵循httpd-vhosts.conf其中写入了以下配置:
<VirtualHost 192.168.1.11:80>
ServerName www.test1.com
DocumentRoot /www/test1/
<Directory "/www/test1">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
<VirtualHost 192.168.1.12:80>
ServerName www.test1.com
DocumentRoot /www/test2/
<Directory "/www/test2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
<VirtualHost 192.168.1.13:80>
ServerName www.test1.com
DocumentRoot /www/test3/
<Directory "/www/test3">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow From All
2.基于主机名
- 将域名映射设置为相同IP,修改hosts:
192.168.1.10 www.test1.com
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com
- 如上所述,为虚拟主机建立网页的根目录。
/www/test1/1.html
/www/test2/2.html
/www/test3/3.html
- 在httpd.conf资料将附在附件中。httpd-vhosts.conf包括、遵循httpd-vhosts.conf其中写入了以下配置:
为了使用基于域名的虚拟主机,您必须指定服务器。IP使主机接受请求的地址(和可能的端口)。可以使用NameVirtualHost配置说明。 如果全部IP将使用地址, 你可以用*作为NameVirtualHost参数。在……里面NameVirtualHost说明中指出的IP该地址不会导致服务器自动监听IP地址。 背景设在这里IP该地址必须与服务器上的网络接口相对应。
下一步是设置您构建的每个虚拟主机。
如果在现有的web向服务器添加虚拟主机还必须为现有主机构建一个虚拟主机。
NameVirtualHost :80
<VirtualHost :80>
ServerName *
DocumentRoot /www/
<VirtualHost *:80>
ServerName www.test1.com
DocumentRoot /www/test1/
<Directory "/www/test1">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<VirtualHost *:80>
ServerName www.test2.com
DocumentRoot /www/test2/
<Directory "/www/test2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
<VirtualHost *:80>
ServerName www.test3.com
DocumentRoot /www/test3/
<Directory "/www/test3">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
- 测试下的每个虚拟主机都是单独访问的。www.test1.com、www.test2.com、www.test3.com
3.基于端口的
1. 修改配置文件
将原来的
Listen 80
改为
Listen 80
Listen 8080
- 更改虚拟主机设置:
<VirtualHost 192.168.1.10:80>
DocumentRoot /var/www/test1/
ServerName www.test1.com
<VirtualHost 192.168.1.10:8080>
DocumentRoot /var/www/test2
ServerName www.test2.com
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除