CentOS 7 Apache服务配置

Apache服务配置

实验目标
1.安装Apache服务
2.配置个人主机网站
3.配置虚拟主机网站

1. 安装Apache服务

yum -y install httpd
[root@master ~]# rpm -qa|grep httpd
httpd-2.4.6-93.el7.centos.x86_64
httpd-tools-2.4.6-93.el7.centos.x86_64

测试一下
启动httpd服务

[root@master ~]# service httpd start

在这里插入图片描述
网站进入待编辑状态,服务启动成功

2. 配置个人网站

设置Apache服务环境项目

[root@master ~]# vim /etc/httpd/conf/httpd.conf

根据需求更改

 83 # e-mailed.  This address appears on some server-generated pages, such
 84 # as error documents.  e.g. admin@your-domain.com
 85 #
 86 ServerAdmin root@localhost	#这里的注释去掉
 87 
 88 #

打开配置文件,启动用户个人网站

[root@master conf.d]# vim /etc/httpd/conf.d/userdir.conf

 13     # UserDir is disabled by default since it can confirm the presence
 14     # of a username on the system (depending on home directory
 15     # permissions).
 16     #
 17     #UserDir disabled	注释掉这行
 18 
 19     #
 20     # To enable requests to /~user/ to serve the user's public_html
 21     # directory, remove the "UserDir disabled" line above, and uncomment
 22     # the following line instead:
 23     # 
 24     UserDir public_html		#启动这一行的服务

退出vi,重启服务

[root@master conf.d]# service httpd restart

创建个人网站

[root@master conf.d]# useradd rixia   #创立个人用户
[root@master conf.d]# 
[root@master conf.d]# su - rixia	
[rixia@master ~]$ mkdir public_html		#在根目录下建立网站目录
[rixia@master ~]$ chmod 755 public_html	#设置主目录额访问权限
[rixia@master ~]$ chmod 755 ~		#设置家目录的访问权限
[rixia@master ~]$ cd public_html
[rixia@master public_html]$ echo "ueser rixia test" >>index.html	#创建主页网站内容
[rixia@master public_html]$ ll
total 4
-rw-rw-r--. 1 rixia rixia 17 Jul  8 07:31 index.html	#已创建的文件

重启服务进行测试

[root@master public_html]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service

在这里插入图片描述
应该是前面的配置还有些权限没有打开。。。
经查询后知道是selinux处于开启状态,处于系统安全考虑,用户只能访问//var/www目录。

进入selinux配置文件

[root@master conf.d]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disable		#改成disable
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

退出vi, 输入命令setenforce 0
[root@master conf.d]# setenforce 0
生效
在这里插入图片描述
这里已经可以看到我们写的内容

3.配置虚拟主机

虚拟主机指的是,在一台主机上运行多个web站点,且各个站点相对独立
进入配置文件

root@master rixia1]# vim /etc/httpd/conf.d/virtual.conf

这里的文件是空的,全部需要自己敲

NameVirtualHost *:80

<Directory "/var/www/rixia1">
        Options FollowSymLinks	#让此目录下的链接允许链接到目录外
        AllowOverride None		#不可复写权限设置
        require all granted		#全部请求可允许
</Directory>

<Directory "/var/www/rixia2">
        Options FollowSymLinks
        AllowOverride None
        require all granted
</Directory>

<VirtualHost *:80>
        ServerName master.example.com	#虚拟主机域名
        DocumentRoot /var/www/html		#虚拟主机的主目录
</VirtualHost>

<VirtualHost *:80>
        ServerName www.rixia1.com
        DocumentRoot /var/www/rixia1
        CustomLog /var/log/httpd/www.access_log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName www.rixia2.com
        DocumentRoot /var/www/rixia2
</VirtualHost>

这里还要设置一下虚拟主机的ip地址(这边在DNS配置里面,应该可以独立设置一个ip,待求实)

[root@master rixia1]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.26.128 www.rixia1.com
192.168.26.128 www.rixia2.com
~                         

重启服务

[root@master rixia1]# service httpd restart

在这里插入图片描述
在这里插入图片描述
实验完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值