使用apache配置基于IP地址的虚拟主机

来源:互联网 发布:mac桌面不见 编辑:程序博客网 时间:2024/06/05 05:16

使用apache配置基于IP地址的虚拟主机

第一步:设置多个IP地址

这里设置两个IP地址:192.168.1.5 和 192.168.1.8

第二步:在 httpd.conf 文件中加入如下内内容

<VirtualHost 192.168.1.5>

DocumentRoot /var/www/html/ip5

</VirtualHost>

<VirtualHost 192.168.1.8>

DocumentRoot /var/www/html/ip8

</VirtualHost>

第三步:在 /var/www/html/ 下新建 ip5 文件夹和ipd8文件夹

cd /var/www/html

mkdir ip5 ip8

第四步:在 ip5 文件夹与 ip8 文件夹下分别建 index.html

在 ip5 文件夹,index.html 内容如下:

<html>

<body>

<p> ip = 192.168.1.5 </p>

<body>

</html>

 

在 ip8 文件夹,index.html 内容如下:

<html>

<body>

<p> ip = 192.168.1.8</p>

<body>

</html>

第五步:重启 httpd

service httpd restart

 

第六步:用浏览器测试。

输入:192.168.1.5,会显示

 ip = 192.168.1.5 

 

输入:192.168.1.8,会显示

 ip = 192.168.1.8 

0 0
原创粉丝点击