通过虚拟主机host文件修改apache配置

手册/FAQ (489) 2016-05-06 11:33:14

 1. 假设服务器有个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

 

 2. 修改hosts文件,添加三个域名与之一一对应:

192.168.1.11   www.test1.com
192.168.1.12   www.test2.com
192.168.1.13   www.test3.com

 

 3. 建立虚拟主机存放网页的根目录,如在/www目录下建立test1、test2、test3文件夹,其中分别存放1.html、2.html、3.html

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

 

 4. 在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
   </Directory>
</VirtualHost>

<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
   </Directory>
</VirtualHost>

<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
   </Directory>
</VirtualHost>

复制代码

THE END