栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 系统运维 > 运维 > Linux

第三本 第三章 Apache的管理及优化web

Linux 更新时间:发布时间: 百科书网 趣学号

Apache的安装

dnf install httpd -y 
 systemctl enable --now httpd  
   firewall-cmd --permanent --add-service=http
   firewall-cmd --permanent --add-service=https
将两个服务加入火墙
   firewall-cmd --reload

 修改测试页内容

vim /var/www/html/index.html 

Apache的基本配置
1.更改Apache端口

vim /etc/httpd/conf/httpd.conf

 

 systemctl restart httpd
 netstat  -antlupe |grep httpd    查看端口

 

 2.默认发布文件的管理

cd /var/www/html/

ls

index.html

vim cui.html

vim /etc/httpd/conf/httpd.conf

167行

systemctl restart httpd

  1. 优先访问cui

  2. 想要访问index要输入完整目录

 

 

默认发布目录的管理 
 

mkdir /westos_apache

ls

cd westos_apache/

vim index.html

建立新目录

 

修改配置文件
vim /etc/httpd/conf/httpd.conf
 

documentRoot "/westos_apache"

 
    # Allow open access:
    Require all granted


semanage fcontext -a -t httpd_sys_content_t '/westos_apache(/.*)?'
将文件类型改为apache识别的类型
    restorecon -RF /westos_apache/
   systemctl restart httpd
效果测试:

Apache的访问控制

在html下建立westos目录

vim /etc/httpd/conf/httpd.conf

122行

documentRoot "/var/www/html"

  Order Allow,Deny
  Allow from all
Deny from 172.25.254.12


 Allow和Deny的读取顺序:
允许任何人访问
不允许172。25。254。12访问
##因为先读Allow后读Deny那么Deny里面的信息会覆盖Allow中的信息

(1)黑名单
  效果测试:真机无法访 

 (2)白名单

  1. vim /etc/httpd/conf/httpd.conf

  2. systemctl restart httpd

 

查看效果

 5.基于用户的访问方式
  1.  建立apache的目录认证文件

实验材料准备:

cd /var/www/html
htpasswd -cm /etc/httpd/.htpasswd admin
##当认证文件不存在时,需要加-c参数
htpasswd -m /etc/httpd/.htpasswd lee
##当认证文件存在时,加-c参数会删除原有内容
cat /etc/httpd/.htpasswd
##查看用户认证文件
 

2.配置文件修改

基本认证
只有admin用户可以通过认证
所有用户可以通过认证

AuthUserFile /etc/httpd/.htpasswd    ##指定认证文件
AuthName “Please input username and passwd” ##指定认证提示
AuthType basic  ##指定认证类型
1.  # Require user admin  ##指定认证用户
##认证文件中admin用户可以通过认证
2.  Require valid-user   ##认证文件中的所有用户都可以通过认证
##两个参数指定写一个就好

 情况一:

 

情况二:

 

 

 

Apache的虚拟主机

1.实验素材

 配置文件内容: 写完了重启服务

vim  /etc/http/conf.d/vhost.conf


documentRoot "/var/www/html"
Customlog logs/default.log combined

 

ServerName wenku.westos.org
documentRoot "/var/www/vhost/wenku"
Customlog logs/wenku.log combined

 

documentRoot "/var/www/vhost/news"
Customlog logs/news.log combined

域名解析:浏览器所在主机中操作

vim  /etc/hosts

172.25.254.112 news.westos.org wenku.westos.org

 

 

 

 

七、Apache的语言支持:

PHP语言
安装php,添加php发布文件内容如下,重启服务即可访问

 

 cgi语言
安装cgi语言的解释器:
创建cgi的发布目录

 

更改cgi的发布文件: 

 

在http.conf中,定义的pl运行位置是/var/www/cgi-bin/,而现在,运行的位置变化了,需要重新说明: 

 

访问一下: 

 

#squid正向代理
1.能上网的主机是代理

代理的操作

vim /etc/sysconfig/network-scripts/ifcfg-ens3

DEVICE=ens3
onBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.112
PREFIX=24
GATEWAY=172.25.254.250
DNS1=114.114.114.114
                 重新加载网络

dnf  install squid -y
  vim /etc/squid/squid.conf
 5965行修改

 

systemctl  restart squid
   48  firewall-cmd --permanent --add-port=3128
   49  firewall-cmd --permanent --add-port=3128/tcp
   50  firewall-cmd --reload 

客户端:

直接在浏览器修改

references  >   network settings  > 

 

 效果测试:客户端ping不通baidu,但是浏览器可以用

 

 #squid反向代理
原理:把westosb作为代理,westosa是主服务器,用户访问westosa时,显示的是westob中的内容

1.代理端:

dnf install httpd.x86_64 -y
   48  echo 172.25.254.212 > /var/www/html/index.html
   52  systemctl stop --now firewalld.service
   54  systemctl enable --now httpd

 2.主服务器:修改配置文件

vim /etc/squid/squid.conf

修改好后
systemctl  restart  squid

http_port 80 vhost vport
cache_peer 172.25.254.212 parent 80 0 proxy-only

 

 systemctl disable --now squid

服务关闭后网页消失

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/461296.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号