Apache
1.Apache的作用
在web被访问时通常使用http://的方式,http://即超文本传输协议。
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。
服务器端软件一般有:Apache、nginx、stgw、jfe、Tengine
查看网站服务器种类:
curl -I 163.com/baidu.com/taobao.com
2.Apache的安装及启用
安装:
dnf install -y httpd
启用:
systemctl enable --now httpd #开启服务并设定无复开机自启
firewall-cmd --permanent --add-service=http #在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https #在火墙中永久开启https访问
firewall-cmd --reload #刷新火墙使设定生效
firewall-cmd --list-all #查看是否生效
3.Apache的基本信息
服务名称 | httpd |
---|---|
主配置文件 | /etc/httpd/conf/httpd.conf |
子配置文件 | /etc/httpd/conf.d/*.conf |
默认发布目录 | /var/www/html |
默认发布文件 | index.html |
默认端口 | http:80/https:443 |
查询端口 | netstat -antlupe \ grep httpd / ss -antlupe \ grep httpd |
用户 | apache |
查询用户 | ps aux \ grep httpd |
日志 | /etc/httpd/logs |
4.Apache的基本配置
4.1端口修改
vim /etc/httpd/conf/httpd.conf
Listen 80 ---> 8080 #更改端口
firewall-cmd --permanent --add-port=8080/tcp #在火墙中添加端口
firewall-cmd --reload
systemctl restart httpd
注意:8080端口是被用于WWW代理服务的,可以实现网页浏览,经常在访问某个网站或使用代理服务器的时候,会加上“:8080”端口号。另外Apache Tomcat web server安装后,默认的服务端口就是8080。
4.2默认发布文件
默认发布文件如果不存在,访问的内容为测试页; 默认发布文件如果存在,访问的内容为文件内容。
可在配置文件中更改默认发布文件:
vim /var/www/html/test.html ---> hello test
vim /var/www/html/index.html ---> hello lee
vim /etc/httpd/conf/httpd.conf
DirectoryIndex test.html index.html #这里会先访问前面的默认发布文件,如果失效再访问后面的
systemctl restart httpd
4.3默认发布目录
更改配置文件,指定默认发布目录位置并授权
mkdir -p /westos/html
cd /westos/html
vim index.html
cat index.html
hello testpage #在自定义位置写文件
vim /etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html"
DocumentRoot "/westos/html"
<Directory "/westos/html">
Require all granted
</Directory> #更改配置文件
systemctl restart httpd
5.Apache的访问控制
5.1基于客户端ip的访问控制:
vim /etc/httpd/conf/httpd.conf
5.1.1 ip白名单在配置文件中的更改
先读deny,再读allow,允许172.25.254.129访问
<Directory "/westos/html">
Order Deny,Allow
Allow from 172.25.254.129
Deny from All
</Directory>