Apache的管理及优化web

目录

1.Apache的作用

2.Apache的安装

3.Apache的启用

4.Apache的基本信息

5.Apache的基本配置

6.Apache的访问控制

 7.Apache的虚拟主机

​ 8.Apache的语言支持


1.Apache的作用

在web被访问时通常使用http://的方式
http://                            ##超文本传输协议

http:// 超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

2.Apache的安装

dnf install httpd.x86_64 -y

3.Apache的启用

systemctl enable --now httpd       ##开启服务并设定服务位开机启动
firewall-cmd --list-all                      ##查看火墙信息
firewall-cmd --permanent --add-service=http  ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload             ##刷新火墙使设定生效

 index.html 写入hello westos

 然后在浏览器中输入172.25.254.200看到hello westos

 

4.Apache的基本信息

服务名称:httpd
配置文件:
                   /etc/httpd/conf/httpd.conf        ##主配置文件(里面有文件信息)
                   /etc/httpd/conf.d/*.conf           ##子配置文件

vim /etc/httpd/conf/httpd.conf

用户:   apache 

 默认发布目录: /var/www/html

默认发布文件: index.html 


默认端口:80    #http


日志:  /etc/httpd/logs

5.Apache的基本配置

(1)Apache端口修改
vim /etc/httpd/conf/httpd.conf
Listen 8080


firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd

 http://172.25.254.200:8080看到index.html的内容

(2)默认发布文件

vim /etc/httpd/conf/httpd.conf 添加test.html为默认发布文件

systemctl restart httpd 

 测试:浏览器中输入172.25.254.200 先执行test.html 若删掉rm -fr test.html 则执行index.html

若删掉rm -fr test.html 则执行index.html

(3)默认发布目录

先建立一个目录

切换到目录下 vim index.html 写入/www/westos/ yy

查看selinux的模式为enforcing,需要修改安全上下文

vim /etc/httpd/conf/httpd.conf 写入DocumentRoot "/www/westos"注释掉默认的 (改变发布目录) 

在浏览器中查看不到

 cat /etc/httpd/logs/error_log##查看报错日志

vim /etc/httpd/conf/httpd.conf 

 systemctl restart httpd

测试:

6.Apache的访问控制

#实验素材#
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html

测试:

 (1)基于客户端ip的访问控制

vim /etc/httpd/conf/httpd.conf
  写入<Directory "/var/www/html/westos">
  Order allow,deny      ##先检查允许设定,允许所有之后禁止73主机访问
  Allow from all
  Deny from 172.25.254.73
</Directory>

systemctl restart httpd 

测试:73主机不可以访问,其他的可以

 cat /etc/httpd/logs/error_log 查看不能访问的用户连接报错信息

 vim /etc/httpd/conf/httpd.conf

写入<Directory "/var/www/html/westos">
  Order deny ,allow     ##先检查禁止设定,禁止73主机访问但是允许所有访问,所以最终是所有都可以访问
  Allow from all
  Deny from 172.25.254.73
</Directory>

systemctl restart httpd 

cat /etc/httpd/logs/access_log 查看访问信息

(2)基于用户认证 

htpasswd -cm /etc/httpd/.htpasswd admin ##创建用户admin的认证文件

htpasswd -m /etc/httpd/.htpasswd lee 如果要创建多个用户密码文件,则不需要加c否则会覆盖原文件内容

vim /etc/httpd/conf/httpd.conf写入

<Directory "/var/www/html/westos">
  AuthUserFile "/etc/httpd/.htpasswd"     ##指定认证文件
  AuthName "Please input username and password !!" ##认证提示语
  AuthType basic             ##认证类型
  Require user lee           ##允许通过的认证用户
# Require valid-user
</Directory>

 systemctl restart httpd

测试:用户lee 可以访问172.25.254.200/westos而admin 不行

 vim /etc/httpd/conf/httpd.conf写入 Require valid-user 则用户都可以

systemctl restart httpd 

测试:

 7.Apache的虚拟主机

mkdir -p /var/www/virtual/westos.org/{linux,luck}
echo linux.westos.org > /var/www/virtual/westos.org/linux/index.html
echo luck.westos.org > /var/www/virtual/westos.org/luck/index.html

vim /etc/httpd/conf.d/vhosts.conf

<VirtualHost *:80>  *表示必须指定名字
   ServerName linux.westos.org ##服务名
   DocumentRoot /var/www/virtual/westos.org/linux ##文件发布目录
   CustomLog logs/linux.log combined ##所有日志结合起来
</VirtualHost>

测试:
在浏览器所在主机中root用户下进行域名解析
vim /etc/hosts ##将常用的网址的域名与其对应的ip地址建立一个关联的数据库
172.25.254.200 utility.example.com www.westos.org linux.westos.org luck.westos.org

 在浏览器中输入

 8.Apache的语言支持

php

vim /var/www/html/index.php 写入

在浏览器中输入172.25.254.219/index.php 显示为空

 dnf install php -y
systemctl restart httpd


cd /etc/httpd/conf.d/  有php.conf 配置文件
php -m ##查看php扩展(加载的模块)


dnf search php 有php数据库

 测试:在浏览器中输入172.25.254.219/index.php 显示php测试页面

 cgi

  在浏览器中静态显示hello westos date 不能执行date 这个命令

 dnf install httpd-manual -y ##安装httpd手册

systemctl restart httpd 

浏览器中可以打开172.25.254.200/manual/

 

 vim index.cgi 写入

 查看cgi的安全上下文标签为httpd_sys_script_exec_t:s0

semanage  fcontext  -a  -t  httpd_sys_script_exec_t  '/var/www/html/cgi(/.*)?' 

restorecon -RvvF /var/www/html/cgi/

 vim /etc/httpd/conf.d/vhosts.conf

systemctl restart httpd 

测试:172.25.254.200/cgi/index.cgi
date 动态显示

 wsgi

dnf search wsgi
dnf install python3-mod_wsgi.x86_64 -y

systemctl restart httpd 

vim /var/www/html/wsgi/index.wsgi  写入phyon代码

 vim /etc/httpd/conf.d/vhosts.conf  写入配置文件

 systemctl restart httpd

在测试机中vim /etc/hosts加入域名解析

 测试:在浏览器中输入wsgi.westos.org

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值