环境:centos7.5
一、安装
1.1 安装Apache服务(Apache软件安装包叫httpd)
[root@localhost ssh]# yum install httpd -y1.2 开启Apache服务[root@localhost ~]# systemctl start httpd
1.3 设置开机自启Apache服务[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.用浏览器查看,本机的登录127.0.0.1,我的是虚拟机所以登录虚拟机IP。

二、相关配置。
2.1 配置目录及相关配置文件:
| 服务目录 | /etc/httpd |
| 主配置文件 | /etc/httpd/conf/httpd.conf |
| 网站数据目录 | /var/www/html |
| 访问日志 | /var/log/httpd/access_log |
| 错误日志 | /var/log/httpd/error_log |
| ServerRoot | 服务目录 |
| ServerAdmin | 管理员邮箱 |
| User | 运行服务的用户 |
| Group | 运行服务的用户组 |
| ServerName | 网站服务器的域名 |
| DocumentRoot | 网站数据目录 |
| Listen | 监听的IP地址与端口号 |
| DirectoryIndex | 默认的索引页页面 |
| ErrorLog | 错误日志文件 |
| CustomLog | 访问日志文件 |
| Timeout | 网页超时时间,默认为300秒. |
| Include | 需要加载的其他文件 |
从上面表格中可以得知DocumentRoot正是用于定义网站数据保存路径的参数,其参数的默认值是把网站数据存放到了/var/www/html目录中的,而网站首页的名称应该叫做index.html,因此可以手动的向这个目录中写入一个文件来替换掉httpd服务程序的默认网页,这种操作是立即生效的
echo "hello everyone my name is feixiangkeji" > /var/www/html/index.html
在/var/www/html/ vi index.html<h1>hello steven</h1>
<a href="list.html">list</a>vi list.html
<h1>this is list</h1>


2.2 修改网站目录。
2.2.1 创建目录 mkdir /steven/test -p, 然后找一个html模板,或者自己手动创建一个index.html,放在此目录下。
2.2.2 修改配置文件,修改两个DocumentRoot位置的参数;如下:
root@localhost test]# vi /etc/httpd/conf/httpd.conf

然后刷新网页,并没有改变;需关闭SELinux并重启httpd服务
httpd服务程序的功能就是让用户能够访问到网站内容,因此让SELinux对网页访问功能肯定是默认允许的,但刚刚把保存网站数据的默认路径修改为了/home/wwwroot目录,这似乎就产生问题了,也就是说现在httpd提供的网站服务却要去获取普通用户家目录中的数据了,这个行为触犯SELinux服务的监管项目。既然已经找出问题所在了
2.2.3
[root@localhost test]# setenforce 0
[root@localhost test]# systemctl restart httpd
[root@localhost test]# getenforce
Permissive
刷新网页:

======================================================================================
本文介绍如何在 CentOS 7.5 上安装和配置 Apache Web 服务器,包括安装服务、设置开机启动及修改网站目录等步骤。此外还提供了常见配置参数的说明。

被折叠的 条评论
为什么被折叠?



