Apache网页与安全优化 网页优化 修改Apache主配置文件加载压缩功能 配置缓存功能 配置隐藏版本和防盗链

Apache网页与安全优化

一、配置Apache的压缩

切换光盘Linux.iso

mount /dev/sr0 /mnt/

解压

tar zxvf /mnt/httpd-2.2.17.tar.gz -C /usr/src/

进入/usr/src/httpd-2.2.17/

cd /usr/src/httpd-2.2.17/

配置

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-charset-liste

编译安装

make && make install

创建链接

ln -s /usr/local/httpd/bin/* /usr/local/bin/

复制主配置文件

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

增加执行权限

chmod +x /etc/init.d/httpd 

编辑主配置文建

vim /etc/init.d/httpd 
#chkconfig:35 20 81
#description:Apache Server

添加httpd服务

chkconfig --add httpd
chkconfig --level 35 httpd on

启动httpd服务

systemctl start htttpd
systemctl enable httpd

查看服务

[root@centos01 ~]# netstat -anput | grep 80

在这里插入图片描述
1)配置apache支持压缩功能
切换光盘centos7.4
安装依赖程序

[root@centos01 ~]# yum -y install zlib-devel

过滤模块

[root@centos01 ~]# apachectl -t -D DUMP_MODULES | grep "dflate"

重新配置 进入/usr/src/httpd-2.2.17/

[root@centos01 ~]# cd /usr/src/httpd-2.2.17/

配置压缩功能

[root@centos01 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-charset-liste --enable-deflate

安装apache

[root@centos01 httpd-2.2.17]# make && make install

检查deflate模块

[root@centos01 ~]# apachectl -t -D DUMP_MODULES | grep "deflate"

在这里插入图片描述

修改Apache主配置文件加载压缩功能

备份配置文件

[root@centos01 ~]# cp /usr/local/httpd/conf/httpd.conf /usr/local/httpd/conf/httpd.conf.bak

编辑配置文件

[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf

跳转到最后一行 :$ 或者 shift+G
添加以下内容

AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml text/javascript //对什么样的内容启动gzip压缩
DeflateCompressionLevel 9 //压缩级别
SetOutputFilter DEFLATE //启动deflate模块对本站的输出进行gzip压缩

检查配置文件–显示ok就可以

[root@centos01 ~]# apachectl -t

在这里插入图片描述
重新启动服务

[root@centos01 ~]# systemctl restart httpd

查看服务

[root@centos01 ~]# netstat -anput | grep 80

配置缓存功能

开启缓存
先查看有没有开启》》》并没有
[root@centos01 ~]# apachectl -t -D DUMP_MODULES | grep “expires”
在这里插入图片描述
去配置expires
进入/usr/src/httpd-2.2.17/

[root@centos01 ~]# cd /usr/src/httpd-2.2.17/

编译配置

[root@centos01 httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-charset-liste --enable-deflate  --enable-expires 

编译安装》》》安装前把httpd服务关闭

[root@centos01 httpd-2.2.17]# nake && make install

修改apache配置文件开启缓存功能

[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf
413 <IfModule mod_expires.c>  //加载缓存模块
414  ExpiresActive On  //开启缓存功能
415  ExpiresDefault "access puls 60 seconds"  //缓存时间60秒
416 </IfModule>

重启apache服务
在这里插入图片描述

查看缓存模块

[root@centos01 ~]# apachectl -t -D DUMP_MODULES | grep "expires"

在这里插入图片描述
使用抓包工具中Headers》》》Cacge》》》这里会多一个Expires
在这里插入图片描述
我们在查看的时候可以看到apache的版本》》》我们来隐藏他
在这里插入图片描述

二、配置隐藏版本和防盗链

进入主配置文件>>>把397行的注释去掉>>>保存退出

[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf
397 #Include conf/extra/httpd-default.conf 

修改配置文件httpd-default.conf

[root@centos01 ~]# vim /usr/local/httpd/conf/extra/httpd-default.conf
 ServerTokens Full    >>> 56 ServerTokens Prod
 ServerSignature On  >>> 67 ServerSignature Off

重新启动apache服务

[root@centos01 ~]# systemctl restart httpd

检查还有没有版本号》》》只显示apache不显示版本号了
在这里插入图片描述
修改hosts文件

[root@centos02 ~]# vim /etc/hosts
192.168.100.10 www.benet.com
192.168.100.20 www.accp.com

开启centos02 安装Apache

[root@centos02 ~]# yum -y install httpd

启动httpd服务-设置开机自动启动

[root@centos02 ~]# systemctl start httpd
[root@centos02 ~]# systemctl enable httpd

centos01
删除默认主页

[root@centos01 ~]# rm -rf /usr/local/httpd/htdocs/index.html

进入/usr/local/httpd/htdocs/

[root@centos01 ~]# cd /usr/local/httpd/htdocs/

上传一张图片到网站根目录
[root@centos01 htdocs]# rz
编辑index.html

[root@centos01 htdocs]# vim index.html
<img src="image.jpg" />

修改win10客户机的配置文件C:\Windows\System32\drivers\etc》》》hosts

192.168.100.10 www.benet.com
192.168.100.20 www.accp.com

访问测试
在这里插入图片描述
访问www.accp.com
在这里插入图片描述
模仿accp盗用benet的连接
[root@centos02 ~]# vim /var/www/html/index.html

访问accp.com在这里插入图片描述

配置Apache实现防盗链

做一个警告图片
在这里插入图片描述
有人跳转到你的服务器就给他跳转到警告上面
放到根目录下

[root@centos01 htdocs]# rz

在这里插入图片描述
开始配置
编辑主配置文件

[root@centos01 ~]# vim /usr/local/httpd/conf/httpd.conf

找到这行

131 <Directory "/usr/local/httpd/htdocs">

在下面写

132 RewriteEngine On
133 RewriteCond %{HTTP_REFERER} !^http://benet.com/.*$ [NC]
134 RewriteCond %{HTTP_REFERER} !^http://benet.com$ [NC]
135 RewriteCond %{HTTP_REFERER} !^http://www.benet.com/.*$ [NC]
136 RewriteCond %{HTTP_REFERER} !^http://www.benet.com$ [NC]
137 RewriteRule .*\.(gif|jpg|swf|bmp)$ http:www.benet.com/error.jpg [R,NC]

重启服务

[root@centos01 ~]# systemctl restart httpd

测试
访问www.accp.com》》》就访不能访问了
在这里插入图片描述
测试www.benet.com还能不能正常访问》》》没问题
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值