CentOS7配置httpd虚拟主机教程
发表于:2025-11-15 作者:千家信息网编辑
千家信息网最后更新 2025年11月15日,本实验旨在CentOS7系统中,httpd-2.4配置两台虚拟主机,主要有以下要求:(1) 提供两个基于名称的虚拟主机:www1.stuX.com,页面文件目录为/web/vhosts/www1;错误
千家信息网最后更新 2025年11月15日CentOS7配置httpd虚拟主机教程
本实验旨在CentOS7系统中,httpd-2.4配置两台虚拟主机,主要有以下要求:
(1) 提供两个基于名称的虚拟主机:
www1.stuX.com,页面文件目录为/web/vhosts/www1;错误日志为/var/log/httpd/www1/error_log,访问日志为/var/log/httpd/www1/access_log;
www2.stuX.com,页面文件目录为/web/vhosts/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 -vServer version: Apache/2.4.6 (CentOS)Server built: Nov 14 2016 18:04:44[root@host ~]$cat /etc/centos-releaseCentOS Linux release 7.3.1611 (Core)
启动httpd,测试能否正常运行
[root@host ~]$systemctl start httpd.service [root@host ~]$systemctl status httpd.service ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2017-06-01 03:03:12 CST; 5s ago # active 表示正常运行 Docs: man:httpd(8) man:apachectl(8) Process: 6473 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Main PID: 6485 (httpd) Status: "Processing requests..." 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 -DFOREGROUNDJun 01 03:03:11 host systemd[1]: Starting The Apache HTTP Server...Jun 01 03:03:12 host systemd[1]: Started The Apache HTTP Server.使用curl命令访问
[root@host ~]$ip a show ens38 # 查看ip 3: ens38:mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:dc:18:5f brd ff:ff:ff:ff:ff:ff inet 192.168.55.128/24 brd 192.168.55.255 scope global dynamic ens38 valid_lft 1752sec preferred_lft 1752sec inet6 fe80::20c:29ff:fedc:185f/64 scope link valid_lft forever preferred_lft forever[root@host ~]$curl http://192.168.55.128 # 访问 CentOS 7.3
创建指定文件目录
[root@host conf.d]$mkdir -pv /web/vhosts/www1[root@host conf.d]$mkdir -pv /web/vhosts/www2[root@host conf.d]$mkdir -pv /var/log/httpd/www2[root@host conf.d]$mkdir -pv /var/log/httpd/www1
根据要求填写虚拟主机配置信息
# path /etc/httpd/conf.d/vir.conf # 配置文件全路径#virtual host 1 # 虚拟主机1的配置ErrorLog "/var/log/httpd/www1/error_log" CustomLog "/var/log/httpd/www1/access_log" combined # virtual host 2 # 虚拟主机2的配置SetHandler server-status Require all granted Require not ip 192.168.1 ServerName www2.stuX.com DocumentRoot "/web/vhosts/www2" ErrorLog "/var/log/httpd/www2/error_log" CustomLog "/var/log/httpd/www2/access_log" combined Require all granted
创建www1和www2的index页面
[root@host conf.d]$cat /web/vhosts/www1/index.htmlwelcome to www1thank you[root@host conf.d]$cat /web/vhosts/www2/index.html welcome to www2thank you
重载httpd配置文件
[root@host conf.d]$httpd -tSyntax OK[root@host conf.d]$systemctl reload httpd.service
修改客户端主机的hosts文件,以便能解析域名
hosts在windows环境下的路径为C:\Windows\System32\drivers\etc。在该文件中添加两行
192.168.55.128 www1.stuX.com
192.168.55.128 www2.stuX.com
访问结果
图1、访问www1站点
图2、访问www2站点
图3、查看www1站点的访问状态--正常
图4、查看www2站点的访问状态错误
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
主机
文件
配置
虚拟主机
日志
站点
状态
目录
错误
页面
信息
版本
系统
路径
运行
两个
内容
名称
命令
域名
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
什么是网络安全侧重点
手机用wifi连不上游戏服务器
删除数据库js
海澜面试软件开发流程
网络安全周宣传活动
网络安全外包
阴阳师最开始有哪些服务器
金铲铲扫码上号显示服务器爆满
网络安全公司的价值观
如何根据系统配置存储服务器
虹口区网络技术咨询服务优势
百度盘古网络技术有限公司
自上而下的数据库是什么意思
网络安全优化日记
网络安全品牌份额
上海智能网络技术直销价格
ipv6与中国网络安全
沈阳管理软件开发
dos显示mysql数据库表
红茶传奇3数据库编辑工具
广德进口软件开发服务参考价格
软件开发期的主要任务
软件开发进度重要性
元宇宙软件开发
表格内的ex服务器在哪里
虹口区网络技术咨询服务优势
加油站管理系统连不上服务器
电视剧视频软件开发
滁州服务器机箱加工价格
苏州汉民软件开发