apache2.4实战之高级配置

一、虚拟主机配置:
基于IP认证:
本机有两块网卡,也即有两个ip地址:172.16.200.138;192.168.122.1
现在要求浏览器访问172.16.200.138时显示www.a.com;访问192.168.122.1显示www.b.com
1.开启httpd服务,以便于调错。

service httpd start

在这里插入图片描述
2.修改配置文件。

#vim /etc/httpd/conf/http.conf
    124 #<Directory "/www/wang">

将根目录域根目录有关的行注释掉
在这里插入图片描述
并在配置文件末尾配置虚拟主机

   367  <VirtualHost 172.16.200.138:80 >
   368      ServerName www.a.com
   369      DocumentRoot "/web/a.com/htdocs"
   370      options all
   371  </VirtualHost>
   372  <VirtualHost 192.168.122.1:80 >
   373      ServerName www.b.org
   374      DocumentRoot "/web/b.org/htdocs"
   375      options all
   376  </VirtualHost>

在这里插入图片描述

#mkdir /web/{a.com/b.org}/htdocs
#service httpd restart

编辑/web/a.com/dotcs/1.html

<p1>this is a.com</p1>

编辑/web/b.org/dotcs/1.html

<p1>this is b.org</p1>
# chmod 777 /web/
# chmod 777 /web/a.com/
# chmod 777 /web/a.com/htdocs/
# chmod 777 /web/a.com/htdocs/1.html 
# chmod 777 /web/b.org/
# chmod 777 /web/b.org/htdocs/
# chmod 777 /web/b.org/htdocs/
# chmod 777 /web/b.org/htdocs/1.html 
# chmod 777 /web/b.org/htdocs/1.html

验证172.16.200.138/1.html
在这里插入图片描述
验证192.168.122.1/1.html
在这里插入图片描述
是不是很简单呢!!

发布了56 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_41363156/article/details/84489856
今日推荐