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

软件环境

系统: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

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


    ServerAdmin [email protected]
    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


    ServerAdmin [email protected]
    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

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,见下图,成功。

你可能感兴趣的:(Apache,Httpd)