您的位置 首页 技术

apache基于ip配置虚拟主机

首先我们用记事本打开httpd.conf文件 ,该文件在apache的目录下,如: D:\AppServ\Apache2.2\conf,修改如下两处: (推荐学习:apache从入…

首先我们用记事本打开httpd.conf文件 ,该文件在apache的目录下,如: D:\AppServ\Apache2.2\conf,修改如下两处:

(推荐学习:apache从入门到精通)

LoadModule vhost_alias_module modules/mod_vhost_alias.so   //去掉前面的#,意思是启用apache的虚拟主机功能,第203行
Include conf/extra/httpd-vhosts.conf  //去掉#的意思是从httpd-vhosts.conf这个文件导入虚拟主机配置

配置虚拟主机后,不能用localhost 访问,只需要把httpd.conf文件的ServerName localhost:80 那行注释掉就可以了。

基于IP

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.com192.168.1.12   www.test2.com192.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>

完成,现在测试下每个虚拟主机,分别访问www.test1.com、www.test2.com、www.test3.com。

以上就是apache基于ip配置虚拟主机的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/88937.html

为您推荐

返回顶部