阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7.2 利用yum安装配置Apache2.4多虚拟主机

500次阅读
没有评论

共计 3614 个字符,预计需要花费 10 分钟才能阅读完成。

分享在 CentOS 7.2 下利用 yum 安装配置 Apache2.4 多虚拟主机的过程,希望对大家有所启发帮助。

一、安装 Apache

安装

# yum install httpd -y
# rpm -qa httpd

操作步骤:

[root@centos7-1 httpd]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core) 
[root@centos7-1 ~]# yum install httpd -y
Loaded plugins: fastestmirror
…………………………………………………………………………
Dependency Installed:
  httpd-tools.x86_64 0:2.4.6-45.el7.centos                         mailcap.noarch 0:2.1.41-2.el7                        

Complete!
[root@centos7-1 ~]# rpm -qa httpd
httpd-2.4.6-45.el7.centos.x86_64

二、启动测试 Apache

1、启动 apache

[root@centos7-1 ~]# systemctl start httpd.service

2、查看是否启动成功

[root@centos7-1 ~]# ps -ef|grep httpd
root      1739     1  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1740  1739  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1741  1739  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1742  1739  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1743  1739  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1744  1739  0 18:34 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      1749  1112  0 18:37 pts/0    00:00:00 grep --color=auto httpd
[root@centos7-1 ~]# netstat -lntup|grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      1739/httpd 

3、在 Linux 端测试
添加 hosts 解析

[root@centos7-1 ~]# echo "192.168.56.101 centos7-1.com www.centos7-1.com bbs.centos7-1.com blog.centos7-1.com">>/etc/hosts
[root@centos7-1 ~]# tail -1 /etc/hosts
192.168.56.101 centos7-1.com www.centos7-1.com bbs.centos7-1.com blog.centos7-1.com

使用 curl 命令测试

[root@centos7-1 ~]# echo "http://www.$HOSTNAME">/var/www/html/index.html
[root@centos7-1 ~]# cat /var/www/html/index.html 
http://www.centos7-1.com
[root@centos7-1 ~]# curl www.centos7-1.com
http://www.centos7-1.com

三、配置 Apache

1、修改前备份文件

[root@centos7-1 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.$(date +%F)
[root@centos7-1 ~]# ll /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.$(date +%F)
-rw-r--r-- 1 root root 11753 Nov 15 00:53 /etc/httpd/conf/httpd.conf
-rw-r--r-- 1 root root 11753 Jan 10 18:42 /etc/httpd/conf/httpd.conf.2017-01-10
[root@centos7-1 ~]# 

2、配置 httpd 文件
因为在 apache2.4 中变化挺大,和 nginx 一样,可以自定义.conf 文件。
在主配置文件中启用虚拟主机

[root@centos7-1 httpd]# mkdir /etc/httpd/vhost.d/
[root@centos7-1 httpd]# echo "include vhost.d/*.conf"
[root@centos7-1 httpd]# tail -1 /etc/httpd/conf/httpd.conf
include vhost.d/*.conf

虚拟主机配置文件

[root@centos7-1 httpd]# cat ./vhost.d/name.conf 
<VirtualHost *:80>
    ServerAdmin admin@amsilence.com
    DocumentRoot "/var/html/www"
    ServerName www.centos7-1.com
    ErrorLog "/var/httpd/logs/www-error_log"
    CustomLog "/var/httpd/logs/www-access_log" common
</VirtualHost>

<Directory /var/html/www/>
Require all granted
</Directory>

<VirtualHost *:80>
    ServerAdmin admin@amsilence.com
    DocumentRoot "/var/html/bbs"
    ServerName bbs.centos7-1.com
    ErrorLog "/var/httpd/logs/bbs-error_log"
    CustomLog "/var/httpd/logs/bbs-access_log" common
</VirtualHost>

<Directory /var/html/bbs/>
Require all granted
</Directory>

<VirtualHost *:80>
    ServerAdmin admin@amsilence.com
    DocumentRoot "/var/html/blog"
    ServerName blog.centos7-1.com
    ErrorLog "/var/httpd/logs/blog-error_log"
    CustomLog "/var/httpd/logs/blog-access_log" common
</VirtualHost>

<Directory /var/html/blog/>
Require all granted
</Directory>

测试配置文件是否正确

[root@centos7-1 httpd]# /sbin/service httpd configtest
Syntax OK

重新启动 apache 服务

[root@centos7-1 httpd]# systemctl restart httpd.service
[root@centos7-1 httpd]# ps -ef|grep httpd
root      1129     1  2 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1131  1129  0 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1132  1129  0 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1133  1129  0 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1134  1129  0 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache    1135  1129  0 20:40 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root      1138  1112  0 20:40 pts/0    00:00:00 grep --color=auto httpd

四、测试 web 服务

curl 测试

[root@centos7-1 httpd]# for name in www bbs blog;do curl $name.centos7-1.com;done;
http://www.centos7-1.com
http://bbs.centos7-1.com
http://blog.centos7-1.com

ie 浏览器测试

CentOS 7.2 利用 yum 安装配置 Apache2.4 多虚拟主机

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-10/147667.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3614字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19348
评论数
4
阅读量
7812059
文章搜索
热门文章
开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南 大家好,我是星哥。之前介绍了腾讯云的 Code...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板 1Panel:小白轻松构建 Web 服务与面板加固指南 哈喽,我是星哥,经常有人问我不...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话?

星哥带你玩飞牛NAS硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话?

星哥带你玩飞牛 NAS 硬件 01:捡垃圾的最爱双盘,暴风二期矿渣为何成不老神话? 前言 在选择 NAS 用预...
零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face免费服务器+Docker 快速部署HertzBeat 监控平台

零成本上线!用 Hugging Face 免费服务器 +Docker 快速部署 HertzBeat 监控平台 ...
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
安装并使用谷歌AI编程工具Antigravity(亲测有效)

安装并使用谷歌AI编程工具Antigravity(亲测有效)

  安装并使用谷歌 AI 编程工具 Antigravity(亲测有效) 引言 Antigravity...
星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的 NAS 中! 大家对「数据安全感」的需求越来越高 ...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

仅2MB大小!开源硬件监控工具:Win11 无缝适配,CPU、GPU、网速全维度掌控

还在忍受动辄数百兆的“全家桶”监控软件?后台偷占资源、界面杂乱冗余,想查个 CPU 温度都要层层点选? 今天给...
星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的NAS中!

星哥带你玩飞牛 NAS-10:备份微信聊天记录、数据到你的 NAS 中! 大家对「数据安全感」的需求越来越高 ...
240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

  240 元左右!五盘位 NAS 主机,7 代 U 硬解 4K 稳如狗,拓展性碾压同价位 在 NA...
星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

  星哥带你玩飞牛 NAS-16:飞牛云 NAS 换桌面,fndesk 图标管理神器上线! 引言 哈...
把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地

把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地

把小米云笔记搬回家:飞牛 NAS 一键部署,小米云笔记自动同步到本地 大家好,我是星哥,今天教大家在飞牛 NA...