apache2.4实战之高级配置

本文详细介绍如何通过基于IP的虚拟主机配置,在同一台服务器上运行两个不同的网站。具体步骤包括开启httpd服务,修改http.conf配置文件,设置不同的IP地址对应不同的域名,并调整文件权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、虚拟主机配置:
基于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
在这里插入图片描述
是不是很简单呢!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值