一、Apache
1、概念:
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器。是最流行的Web服务器端软件之一,有多种产品,可以支持SSL技术,支持多个虚拟主机。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。
2、特点:
Apache的特点是简单、速度快、性能稳定,并可做代理服务器来使用。它可以在大多数计算机操作系统中运行,由于其跨平台和安全性被广泛使用。
3、Apache web服务器的特性:
1.支持最新的HTTP/1.1通信协议
2.拥有简单而强有力的基于文件的配置过程
3.支持网关接口
4.支持基于IP和基于域名的虚拟主机
5.支持多种方式的HTTP认证
6.集成Perl处理模块
7.集成代理服务器模块
8.支持实时监视服务器状态和定制服务器日志
9.支持服务器端包含指令(SSI)
10.支持安全Socket层(SSL)
11.提供用户会话过程的跟踪
12.支持FastCGI
13.通过第三方模块可以支持JavaServlets
二.Apache的安装部署
实验主机为apache-server,测试为真机浏览器
1、apache服务的基本配置
[root@apache-server ~]# yum install httpd.x86_64 -y #安装http服务
[root@apache-server ~]# systemctl start httpd #启动http服务
[root@apache-server ~]# systemctl enable httpd #开启http服务并设为开机自启动
2、列出火墙信息,并设置永久允许http,htpps
[root@apache-server ~]# firewall-cmd --permanent --add-service=http #添加http到火墙策略
[root@apache-server ~]# firewall-cmd --permanent --add-service=https #添加https到火墙策略
[root@apache-server ~]# firewall-cmd --reload #刷新火墙信息
[root@apache-server ~]# firewall-cmd --list-all #列出火墙信息
**用图形的方式也可以设定:
[root@apache-server ~]# firewall-config #打开火墙图形界面
重启服务
systemctl restart firewalld
在浏览器中输入测试端ip,看到apache已经开启
[root@apache-server ~]# yum install httpd-manual -y # 这是提供apache使用的手册的软件
[root@apache-server ~]# systemctl restart httpd # 重启
网页访问 172.25.254.227/manual/ 即可看到手册内容
在默认发布目录:/var/www/html下建立发布文件
[root@apache-server ~]# cd /var/www/html/ # 这是httpd的默认发布目录
[root@apache-server html]# vim index.html # 这是httpd的默认发布文件
在浏览器中输入测试端ip,可以看到相应的文件内容
三、apache基础信息的修改
apache的基础信息:
- 主配置目录:/etc/httpd/conf
- 主配置文件:/etc/httpd/conf/httpd.conf
- 子配置目录:/etc/http/conf.d
- 子配置文件:/etc/httpd/conf.d/*.conf
- 默认发布目录:/var/www/html
- 默认发布文件:index.html
- 默认监听端口:80
- 默认安全上下文:httpd_sys_content_t
- 程序开启默认用户: apache
- 错误日志 :/var/httpd/log/error_log
配置 httpd 服务程序时最常用的参数以及用途描述:
- DirectoryIndex # 默认的索引页页面
- Directory # 网站数据目录的权限
- ServerRoot # 服务目录
- ServerName # 网站服务器的域名
- Listen # 监听的 IP 地址与端口号
- CustomLog # 访问日志文件
- DocumentRoot # 定义网站数据保存路径
1、修改端口
(1)查看默认监听端口是80
(2)编辑主配置文件
[root@apache-server html]# vim /etc/httpd/conf/httpd.conf
默认是80
修改端口80 ----> 8080
(3)重启服务
[root@apache-server html]# systemctl restart httpd.service
(4)查看端口修改成功
(5)测试:
可以看到,默认的80端口已经无法访问
但是8080端口仍然不可以进行访问
(6)在火墙中允许8080端口
[root@apache-server html]# firewall-cmd --add-port=8080/tcp --zone=public # 在火墙中添加httpd的8080端口
[root@apache-server html]# firewall-cmd --list-all
(7)测试:8080端口可以进行访问
(8)再次主配置文件,修改端口为7777
[root@apache-server html]# vim /etc/httpd/conf/httpd.conf
查看selinux状态,如果为强制模式,则重启服务会失败
[root@apache-server html]# getenforce
Enforcing
警告模式下重启成功,而强制模式下重启失败
这是因为selinux只允许几个特定的端口
[root@apache-server html]# semanage port -l | grep http
selinux添加7777端口
[root@apache-server html]# semanage port -a -t http_port_t -p tcp 7777 # 把7777这个接口添加到gttp的默认接口中
[root@apache-server html]# semanage port -l | grep http
火墙中允许7777端口
[root@apache-server html]# firewall-cmd --add-port=7777/tcp --zone=public # 在火墙中添加httpd的8080端口
[root@apache-server html]# firewall-cmd --list-all