Apache 1
1. Apache 的作用
在Web被访问时通常使用http://的方式
http:// 超文本传输协议
http:// 超文本传输协议提供的软件:
Appche
nginx
stgw
jfe
Tengine
2. Apache的安装
# dnf install httpd.x86_64 -y 安装
3. Apache的启用
# systemctl enable --now httpd 设定服务开启并且开机启动
# systemctl status httpd 查看状态
# firewall-cmd --list-all 查看火墙信息
# firewall-cmd --permanent --add-service=http 在火墙中永久开启http访问
# firewall-cmd --permanent --add-service=https 在火墙中永久开启https访问
# firewall-cmd --reload 刷新服务
# firewall-cmd --list-all 查看火墙信息
4. Apache 的基本信息
服务名称:http
配置文件:/etc/httpd/conf/httpd.conf 主配置文件
/etc/httpd/conf/*.conf 子配置文件
默认发布的目录:/var/www/html
默认端口: 80 http
442 https
用户 Apache
日志 /etc/httpd/logs
5. Apache的基本配置
1. Apache端口修改
# netstat -antlupe | grep httpd 查看端口
# vim /etc/httpd/conf/httpd.conf 编辑配置文件
# firewall-cmd --add-port=6666/tcp 防火墙内允许端口
selinux开启状态有自己的端口列表需要将列表号添加进去
# semanage port -l | grep http
# semanage port -a -t http_port_t -p tcp 1211
# systemctl restart httpd 重启服务
# ss -antlupe | grep httpd 查看端口
2.默认发布文件
在/var/www/html/中新建两个文件
echo hello westos >index.html
echo hello >westos.html
http默认访问到的是index.html文件
# vim /etc/httpd/conf/httpd.conf 修改配置文件
# systemctl restart httpd 重启服务
3. 默认发布目录
新建目录
mkdir -p /westos/html 新建目录
vim /westos/html/index.html
# vim /etc/httpd/conf/httpd.conf 修改配置文件
# systemctl restart httpd 重启服务
发现还是不能访问目录
这时候可以关掉selinux或者改为警告模式,也可以更改安全上下文
更改安全上下文
# ls -Zd /var/www/html/ 查看安全上下文
# ls -Zd /westos/html/
# semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?' 修改安全上下文
# # restorecon -RvvF /westos
6. Apache
实验环境
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
ip白名单(rhe8)
允许自己访问不允许其他人访问
rhel8
# firefox http://192.168.1.32/westos
rhel7
# firefox http://192.168.1.32/westos
ip黑名单(rhel8)
不允许自己访问允许其他人访问
# vim /etc/httpd/conf/httpd.conf 编辑配置文件
rhel8
# firefox http://192.168.1.32/westos
rhel7
# firefox http://192.168.1.32/westos
2. 基于用户的认证
# vim /etc/httpd/conf/httpd.conf 编辑配置文件
# systemctl restart httpd 重启服务
# htpasswd -cm /etc/httpd/htpasswdfile linux 创建认证文件并创建用户
# htpasswd -m /etc/httpd/htpasswdfile westos 创建认证文件并创建用户
-c表示cread已经有了认证文件,重复使用-c的话会清空里面内容
测试
# firefox http://192.168.1.32/westos
指定用户登录
# vim /etc/httpd/conf/httpd.conf 编辑配置文件
# systemctl restart httpd 重启服务
linux不能登录
# firefox http://192.168.1.32/westos