本实验旨在CentOS7系统中,httpd - 2.4配置两台虚拟主机,主要有以下要求:
(1)提供两个基于名称的虚拟主机:
www1.stuX.com页面文件目录为/web/vhost/www1;错误日志为/var/log/httpd/www1/error_log访问日志为/var/log/httpd/www1/access_log;
www2.stuX.com页面文件目录为/web/vhost/www2;错误日志为/var/log/httpd/www2/error_log访问日志为/var/log/httpd/www2/access_log;
(2)通过www1.stuX.com/server-status输出其状态信息,且要求只允许提供账号的用户访问。
(3) www1不允许192.168.1.0/24网络中的主机访问,,
查看系统版本和httpd版本
[root@host ~]美元httpd - v 服务器版本:Apache/2.4.6 (CentOS) 服务器建:2016年11月14日18:04:44 [root@host ~]猫/etc/centos-release美元 Linux CentOS释放7.3.1611(核心)
启动httpd,测试能否正常运行
[root@host ~]美元systemctl httpd.service开始 [root@host ~] httpd.service systemctl美元地位 ●httpd。服务——Apache HTTP服务器 加载:加载(/usr/lib/systemd/系统/httpd.service;启用;厂商预设:禁用) 主动:主动(运行)自清华2017-06-01 03:03:12中科;5 s前#活跃表示正常运行 文档:男:httpd (8) 男:apachectl (8) 过程:ExecStop=/bin/杀死绞车6473 {MAINPID}(状态退出代码=,=0/成功) 主要PID: 6485 (httpd) 状态:“处理请求……” CGroup:/system.slice/httpd.service ├─6485/usr/sbin/httpd -DFOREGROUND ├─6486/usr/sbin/httpd -DFOREGROUND ├─6487/usr/sbin/httpd -DFOREGROUND ├─6489/usr/sbin/httpd -DFOREGROUND ├─6490/usr/sbin/httpd -DFOREGROUND └─6572/usr/sbin/httpd -DFOREGROUND 6月01 03:03:11主机systemd[1]:启动Apache HTTP服务器…… 6月01 03:03:12主机systemd[1]:启动Apache HTTP服务器。 >之前使用curl命令访问
(root@host ~) $ ip显示ens38 #查看ip 3:ens38: & lt;广播、多播、,LOWER_UP>qlen 1000 mtu 1500 qdisc pfifo_fast状态 链接/醚00:0c: 29: dc: 18:5f brd ff: ff: ff: ff: ff: ff 全球动态ens38 inet 192.168.55.128/24 brd 192.168.55.255范围 valid_lft 1752秒preferred_lft 1752秒 inet6 fe80:: 20 c: 29 ff: fedc: 185 f/64范围的链接 valid_lft永远preferred_lft永远 [root@host ~]美元curl http://192.168.55.128访问 & lt; ! DOCTYPE> & lt; h2> CentOS 7.3 & lt;/h2> >之前创建指定文件目录
[root@host conf.d]美元mkdir pv/web/vhost/www1 [root@host conf.d]美元mkdir pv/web/vhost/www2 [root@host conf.d]美元mkdir pv/var/log/httpd/www2 [root@host conf.d]美元mkdir pv/var/log/httpd/www1 >之前根据要求填写虚拟主机配置信息
#路径/etc/httpd/conf.d/vir.参看#配置文件全路径 1 #虚拟主机1 #虚拟主机的配置 & lt;虚拟主机192.168.55.128:80> ErrorLog "/var/log/httpd/www1/error_log” CustomLog "/var/log/httpd/www1/access_log”的总和 & lt;位置/server-status> SetHandler服务器状态 & lt;/Location> & lt;目录/web/vhost/www1> & lt; RequireAll> 要求所有授予 不需要ip 192.168.1 & lt;/RequireAll> & lt;/Directory> & lt;/VirtualHost> 2 #虚拟主机2 #虚拟主机的配置 & lt;虚拟主机192.168.55.128:80> ServerName www2.stuX.com DocumentRoot“/web/vhost/www2” ErrorLog "/var/log/httpd/www2/error_log” CustomLog "/var/log/httpd/www2/access_log”的总和 & lt;目录/web/vhost/www2> & lt; RequireAll> 要求所有授予 & lt;/RequireAll> & lt;/Directory> & lt;/VirtualHost> >之前创建www1和www2的索引页面
[root@host conf.d] $ cat/web/vhost/www1/index . html 欢迎来到www1 谢谢你! [root@host conf.d] $ cat/web/vhost/www2/index . html 欢迎来到www2 谢谢你! >之前重载httpd配置文件
[root@host conf.d]美元httpd - t 语法好 [root@host conf.d] systemctl重载httpd.service美元 >之前,修改客户端主机的主机文件,以便能解析域名
主机在windows环境下的路径为C: \ windows \ System32系统\ \司机等。在该文件中添加两行
192.168.55.128 www1.stuX.com
CentOS7配置httpd虚拟主机教程