CentOS 7系统下Apache服务部署


前言

对前篇博客(十七)进行一个修正与补充


基于不同的端口号,实现多虚拟主机部署并访问

描述 IP地址
Apache服务器 192.168.118.115
116.xxx.com 192.168.118.115:80
117.xxx.com 192.168.118.115:81

一、Apache服务器的部署

Apache 是一个web服务器提供者,web中间件,可在多种操作系统上运行,能够提供html文本文档的传输,传输协议是http/https协议,默认端口:80/443

1.配置yum源

进入yum配置目录

cd /etc/yum.repos.d

创建备份

mkdir backup

将CentOS-* 文件移入备份文件夹

mv CentOS-* backup

新建文件

vim local.repo

文件内容

[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0

卸载光驱

umount /dev/sr0

加载光驱

mount /dev/sr0 /mnt

2.关闭防火墙、网络图形化工具及SElinux

关闭防火墙及禁止防火墙自启

systemctl stop firewalld && systemctl disable firewalld

关闭网络图形化工具

systemctl stop NetworkManager && systemctl disable NetworkManager

查看SElinux状态

getenforce

设置宽容模式(临时关闭SElinux)

setenforce 0

永久关闭SElinux

vim /etc/selinux/config
SELINUX=enforcing 

改为

 SELINUX=disabled

3.配置静态IP

进入网卡配置目录

cd /etc/sysconfig/network-scripts/

编辑网卡配置

vim ifcfg-ens33

文件内容

TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.
PREFIX=24
GATEWAY=
DNS=

配置网卡后重启网络服务

systemctl restart network

4.安装Apache软件包

Apache的软件包为bind

yum -y install httpd

5.核心配置文件

(一)单网页无需多配置即可使用

主配置文件目录为

/etc/httpd/conf/httpd.conf

(二)多网页配置

1)基于不同的端口号
2)基于不同的域名
3)基于不同的IP地址

本片博客是基于不同的端口号配置:
配置虚拟主机头操作如下
创建目录

mkdir /etc/httpd/extra

复制一份文件虚拟主机头配置文件到当前目录

cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/extra

在主配置文件末尾追加

vim /etc/httpd/conf/httpd.conf
IncludeOptional extra/*.conf

将httpd.conf中Listen 80 注释掉

vim /etc/httpd/conf/htppd.conf
#Listen 80

在httpd-vhosts.conf中加入:Listen 80、Listen 81

vim /etc/httpd/extra/httpd-vhosts.conf
listen 80
listen 81
<VirtualHost 192.168.118.115:80>
    ServerAdmin root
    DocumentRoot "/var/www/html/115/"
    ServerName 115.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/var/log/httpd/115.com-error_log"
    CustomLog "/var/log/httpd/115.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.118.115:81>
    ServerAdmin root
    DocumentRoot "/var/www/html/116/"
    ServerName 115.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/var/log/httpd/116.com-error_log"
    CustomLog "/var/log/httpd/116.com-access_log" common
</VirtualHost>

6.重启Apache服务器

systemctl restart httpd

7.客户端接入Apache服务器验证

当客户端设备与Apache服务器处于同一网段时,可通过ip地址进行访问。

猜你喜欢

转载自blog.csdn.net/liujiuwu_xyz/article/details/131681084
今日推荐