CentOS7 yum安装Apache Httpd配置虚拟主机

本文介绍了在CentOS7系统上使用yum安装Apache Httpd 2.4.6-89.el7.centos.1,并详细阐述了如何配置虚拟主机,包括复制和编辑配置文件,创建发布目录,编辑hosts文件以及最终的验证过程。

软件环境

系统:CentOS7

Apache Httpd版本:2.4.6-89.el7.centos.1

Apache Httpd安装方式:yum安装

 

1. 复制虚拟主机配置文件

cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/

2. 编辑虚拟主机配置文件

vi /etc/httpd/conf.d/httpd-vhosts.conf

加入以下代码并把其余的注释掉:

<VirtualHost *:80>
    ServerAdmin support@jfedu.net
    DocumentRoot "/var/www/html/jf1"
    ServerName www.jf1.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/www.jf1.com_error_log"
    CustomLog "logs/www.jf1.com_access_log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin support@jfedu.net
    DocumentRoot "/var/www/html/jf2"
    ServerName www.jf2.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/www.jf2.com_error_log"
    CustomLog "logs/www.jf2.com_access_log" common
</VirtualHost>

3. 创建发布目录和index.html页

mkdir /var/www/html/{jf1,jf2}
echo "www.jf1.com" > /var/www/html/jf1/index.html
echo "www.jf2.com" > /var/www/html/jf2/index.html

4. 重启Httpd

systemctl restart httpd

5. 编辑windows的hosts文件

切换Administrator用户登录windows    操作指南

编辑 c:\Windows\System32\drivers\etc\hosts

加入以下代码:

192.168.100.8 www.jf1.com
192.168.100.8 www.jf2.com

温馨提示:把IP地址替换为自己的

6. 浏览器验证

浏览器访问 www.jf1.com,见下图,成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值