Apache

1.Apache的作用

在web被访问时通常使用http://的方式。

http://即超文本传输协议。

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。

http://超文本传输协议提供软件:
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 pika

vim /etc/httpd/conf/httpd.conf
DirectoryIndex  test.html   index.html
#(注意:这里会先访问前面的默认发布文件,如果失效再访问后面的)

systemctl restart httpd

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.3默认发布目录

更改配置文件,指定默认发布目录位置并授权

[root@node1 ~]# mkdir -p /westos/html
[root@node1 ~]# cd /westos/html
[root@node1 html]# vim index.html
[root@node1 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的访问控制

  1. 基于客户端ip的访问控制:
    vim /etc/httpd/conf/httpd.conf

ip白名单在配置文件中的更改:
先读deny,再读allow,允许172.25.254.128访问

<Directory "/westos/html">        
	Order Deny,Allow        
	Allow from 172.25.254.128       
	Deny from All 
</Directory>

在这里插入图片描述
在这里插入图片描述

ip黑名单在配置文件中的更改:

IP用户黑名单,先读取allow,后读取deny,后读会覆盖先读:不允许172.25.254.128访问。

<Directory "/westos/html">        
	Order Allow,Deny       
    Allow from All        
	Deny from 172.25
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值