千家信息网

怎么在CentOS 8上安装与配置Apache虚拟主机

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,怎么在CentOS 8上安装与配置Apache虚拟主机,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Apache服务器是
千家信息网最后更新 2026年11月02日怎么在CentOS 8上安装与配置Apache虚拟主机

怎么在CentOS 8上安装与配置Apache虚拟主机,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

Apache服务器是现代操作系统包括UNIX和Windows等开发和维护开源的HTTP服务器,apache提供一个安全、高效、可扩展的服务器,提供与当前HTTP标准同步的HTTP服务。

实验环境

操作系统: Centos 8

web应用:apache

内网IP:192.168.3.21

shell执行:root

以root或具有sudo权限的用户身份登录执行如下操作。

安装httpd服务

[root@linuxcool ~]# yum install httpd-devel.x86_64 httpd.x86_64 httpd-tools.x86_64

验证httpd是否安装成功

[root@linuxcool ~]# httpd -v Server version: Apache/2.4.6 (CentOS) Server built:   Apr  2 2020 13:13:23

启动httpd服务

[root@linuxcool ~]# systemctl start httpd.service          [root@linuxcool ~]# systemctl status httpd.service  ● httpd.service - The Apache HTTP Server    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)    Active: active (running) since Fri 2020-05-22 12:23:03 CST; 25s ago      Docs: man:httpd(8)            man:apachectl(8)  Main PID: 952 (httpd)    Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"     Tasks: 6    Memory: 3.6M    CGroup: /system.slice/httpd.service            ├─952 /usr/sbin/httpd -DFOREGROUND            ├─953 /usr/sbin/httpd -DFOREGROUND            ├─954 /usr/sbin/httpd -DFOREGROUND            ├─955 /usr/sbin/httpd -DFOREGROUND            ├─956 /usr/sbin/httpd -DFOREGROUND            └─957 /usr/sbin/httpd -DFOREGROUND May 22 12:23:03 linuxcool systemd[1]: Starting The Apache HTTP Server... May 22 12:23:03 linuxcool httpd[952]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, u...message May 22 12:23:03 linuxcool systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.

apache安装成功,默认web目录/var/www/

测试

http://192.168.3.21/

安装成功!

配置apache虚拟主机创建网站目录

[root@linuxcool ~]# mkdir -p /var/www/web1 [root@linuxcool ~]# mkdir -p /var/www/web2

web1添加index.html

[root@linuxcool ~]# vim /var/www/web1/index.html               Welcome to Web1           

Success! Web1 home page!

web2添加index.html

[root@linuxcool ~]# vim /var/www/web2/index.html               Welcome to Web1           

Success! Web1 home page!

授权web目录权限

[root@linuxcool ~]# chown -R apache: /var/www/web1/ [root@linuxcool ~]# chown -R apache: /var/www/web2/

创建虚拟主机文件

#web1

[root@linuxcool ~]# vim /etc/httpd/conf.d/web1.conf  ServerName web1.com ServerAlias www.web1.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web1  Options -Indexes +FollowSymLinks AllowOverride All  ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined 

#web2

[root@linuxcool ~]# vim /etc/httpd/conf.d/web2.conf  ServerName web2.com ServerAlias www.web2.com ServerAdmin webmaster@example.com DocumentRoot /var/www/web2  Options -Indexes +FollowSymLinks AllowOverride All  ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined 

重启httpd服务

[root@linuxcool ~]# systemctl restart httpd.service

验证httpd虚拟主机结果

http://www.web1.com

http://www.web2.com

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

服务 主机 虚拟主机 成功 服务器 目录 配置 操作系统 权限 系统 帮助 验证 清楚 安全 内容 对此 文件 文章 新手 更多 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广东猪兼强互联网科技有限公司 互联网科技社 为想互联网科技 互联网金融科技创新 科技互联网公司logo 上游互联网科技 撒么互联网科技公司 国外互联网科技网站 深圳前海聚择互联网科技有限公司 广州恒生互联网科技有限 全球顶尖互联网科技公司 互联网科技与管理 苏州五指互联网络科技有限 中国航天科技大学国际工业互联网 新兴科技互联网创新大赛颁奖典礼 国大互联网教育科技有限公司工作 四川互联网展示科技馆设计 卡尔迅互联网科技有限公司 互联网硬科技公司 青岛互联网科技园 互联网科技工作委员会 互联网 卓越科技 四个字互联网科技公司取名 互联网 科技馆 成都玖崟互联网科技有限公司乐商圈怎么样 互联网科技公司营业执照怎么办理 中国互联网有什么科技 电子商务与互联网科技的关系 美国互联网科技公司 亚光科技低轨卫星互联网
0