博主,最近考试。本篇博客详细介绍了,如何用apache进行页面压缩、修改网页缓存时间节省资源、防盗链服务和隐藏版本的来优化LAMP架构。 网页压缩来进一步提升网页的浏览速度,它完全不需要任何的成本,只不过是会让您的服务器CPU占用率稍微提升一两个百分点而已或者更少. 1、首先浏览器请求某个 URL 地址,并在请求的头 (head) 中设置属性 accept-encoding 值为 gzip, deflate,表明浏览器支持 gzip 和 deflate 这两种压缩方式(事实上 deflate 也是使用 gzip 压缩协议); 2、WEB 服务器接收到请求后判断浏览器是否支持压缩,如果支持就传送压缩后的响应内容,否则传送不经过压缩的内容; 3、浏览器获取响应内容后,判断内容是否被压缩,如果是则解压缩,然后显示响应页面的内容。 在实际的应用中我们发现压缩的比率往往在 3 到 10 倍,也就是本来 50k 大小的页面,采用压缩后实际传输的内容大小只有 5 至 15k大小,这可以大大节省服务器的网络带宽。 配置网页的缓存时间概述 客户机网页测试 只有访问IP为192.168.158.30才能获得资源 使用Windows主机测试 攻击者往往是先通过扫描软件的版本信息然后进行针对性的攻击,通常每个版本都不是完美的,所以如果知道版本,就可以进行针对性的攻击,在apache安装完成应该第一时间隐藏它的版本信息 Apache的版本信息,透露了-定的漏洞信息,从而给 将主配置文件httpd.conf以下行注释去掉概述
网页压缩是一项由 WEB 服务器和浏览器之间共同遵守的协议,也就是说 WEB 服务器和浏览器都必须支持该技术,流行的浏览器都是支持的,包括 IE、FireFox、Opera 等;服务器有 Apache 和 IIS 等。双方的协商过程如下:一:网页压缩
1.1:网页压缩zip概述
1.2:Apache的压缩模块
1.3:首先安装apache
[root@server3 ~]# ll 总用量 8032 -rw-------. 1 root root 1907 8月 26 17:58 anaconda-ks.cfg -rw-r--r--. 1 root root 1071074 10月 13 21:35 apr-1.6.2.tar.gz -rw-r--r--. 1 root root 565507 10月 13 21:35 apr-util-1.6.0.tar.gz -rw-r--r--. 1 root root 6567926 10月 13 21:35 httpd-2.4.29.tar.bz2 -rw-r--r--. 1 root root 1955 8月 26 18:30 initial-setup-ks.cfg drwxr-xr-x. 2 root root 6 8月 26 18:31 公共 drwxr-xr-x. 2 root root 6 8月 26 18:31 模板 drwxr-xr-x. 2 root root 6 8月 26 18:31 视频 drwxr-xr-x. 2 root root 6 8月 26 18:31 图片 drwxr-xr-x. 2 root root 6 8月 26 18:31 文档 drwxr-xr-x. 2 root root 6 8月 26 18:31 下载 drwxr-xr-x. 2 root root 6 8月 26 18:31 音乐 drwxr-xr-x. 2 root root 6 8月 26 18:31 桌面 [root@server3 ~]# tar xf apr-1.6.2.tar.gz [root@server3 ~]# tar xf apr-util-1.6.0.tar.gz [root@server3 ~]# tar xf httpd-2.4.29.tar.bz2 [root@server3 ~]# mv apr-1.6.2 httpd-2.4.29/srclib/apr [root@server3 ~]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
1.4:安装编译器和其他工具
[root@server3 ~]# yum -y install gcc gcc-c++ make pcre pcre-devel zlib-devel expat-devel perl
1.5:configure配置
[root@server3 ~]# cd httpd-2.4.29/ [root@server3 httpd-2.4.29]# ls ABOUT_APACHE BuildBin.dsp config.status httpd.mak libhttpd.mak modules.o server acinclude.m4 buildconf configure httpd.spec LICENSE NOTICE srclib Apache-apr2.dsw buildmark.o configure.in include Makefile NWGNUmakefile support Apache.dsw CHANGES docs INSTALL Makefile.in os test apache_probes.d CMakeLists.txt emacs-style InstallBin.dsp Makefile.win README VERSIONING ap.d config.layout httpd LAYOUT modules README.cmake build config.log httpd.dep libhttpd.dep modules.c README.platforms BuildAll.dsp config.nice httpd.dsp libhttpd.dsp modules.lo ROADMAP [root@server3 httpd-2.4.29]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi --enable-cgid --enable-deflate
1.6:make编译make install
[root@server3 httpd-2.4.29]# make && make install
1.7:修改配置文件
[root@server3 ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd [root@server3 ~]# vi /etc/init.d/httpd [root@server3 ~]# chkconfig --add httpd [root@server3 ~]# ln -s /usr/local/httpd/conf/ /httpd.conf /etc/ [root@server3 ~]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@server3 ~]# vi /usr/local/httpd/conf/httpd.conf LoadModule headers_module modules/mod_headers.so#/搜索/deflate,若没有,需要检查之前配置重新编译 搜索就取消注释 末行添加 ADDOutputFilterByType DEFLATE text/html eext/css text/plain text/xml text/javascript image/png image/jpg image/jepg image/gif application/x-httpd-php application/x-javascript DeflateCompressionLevel 9 SetOutputFilter DEFLATE
1.8:验证语法重启服务
[root@server3 ~]# httpd -t [root@server3 ~]# systemctl stop firewalld.service [root@server3 ~]# setenforce 0 [root@server3 ~]# systemctl start httpd [root@server3 ~]# netstat -anpt |grep 80 tcp6 0 0 :::80 :::* LISTEN 36409/httpd
1.9:编辑测试网页
测试网页放入一张图片 [root@server3 ~]# cd /usr/local/httpd/htdocs/ [root@server3 htdocs]# ll 总用量 4900 -rw-r--r--. 1 root root 2506246 10月 13 22:48 20201013120035500.png -rw-r--r--. 1 root root 2506246 10月 13 22:39 a.png -rw-r--r--. 1 root root 76 10月 13 22:50 index.html [root@server3 htdocs]# cat index.html <html><body><h1>apache</h1><img src="20201013120035500.png"/></body></html>
发现网页支持压缩二:网页缓存
2.1:Apache网页缓存实验
[root@server3 ~]# ll 总用量 8032 -rw-------. 1 root root 1907 8月 26 17:58 anaconda-ks.cfg -rw-r--r--. 1 root root 1071074 10月 13 21:35 apr-1.6.2.tar.gz -rw-r--r--. 1 root root 565507 10月 13 21:35 apr-util-1.6.0.tar.gz -rw-r--r--. 1 root root 6567926 10月 13 21:35 httpd-2.4.29.tar.bz2 -rw-r--r--. 1 root root 1955 8月 26 18:30 initial-setup-ks.cfg drwxr-xr-x. 2 root root 6 8月 26 18:31 公共 drwxr-xr-x. 2 root root 6 8月 26 18:31 模板 drwxr-xr-x. 2 root root 6 8月 26 18:31 视频 drwxr-xr-x. 2 root root 6 8月 26 18:31 图片 drwxr-xr-x. 2 root root 6 8月 26 18:31 文档 drwxr-xr-x. 2 root root 6 8月 26 18:31 下载 drwxr-xr-x. 2 root root 6 8月 26 18:31 音乐 drwxr-xr-x. 2 root root 6 8月 26 18:31 桌面 [root@server3 ~]# tar xf apr-1.6.2.tar.gz [root@server3 ~]# tar xf apr-util-1.6.0.tar.gz [root@server3 ~]# tar xf httpd-2.4.29.tar.bz2 [root@server3 ~]# mv apr-1.6.2 httpd-2.4.29/srclib/apr [root@server3 ~]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
2.2:安装编译器和其他工具
[root@server3 ~]# yum -y install gcc gcc-c++ make pcre pcre-devel zlib-devel expat-devel perl
2.3:configure配置
./configure --prefix=/usr/local/httpd --enable-deflate --enable-expires --enable-so --enable-rewrite --enable-charset-lite --enable-expires #
2.4:make编译make install
[root@server3 httpd-2.4.29]# make && make install
2.5:修改配置文件
[root@server3 httpd-2.4.29]# vi /etc/httpd.conf LoadModule expires_module modules/mod_expires.so #去掉前面注释 #末行添加 <IfModule mod_expires.c> ExpiresActive On #开启缓存功能 ExpiresDefault "access plus 60 seconds" #保持60s </IfModule>
2.6:重启服务
[root@server3 httpd-2.4.29]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9a22:5aea:2642:6dff. Set the 'ServerName' directive globally to suppress this message Syntax OK [root@server3 httpd-2.4.29]# apachectl -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9a22:5aea:2642:6dff. Set the 'ServerName' directive globally to suppress this message Syntax OK [root@server3 httpd-2.4.29]# netstat -anpt | grep httpd tcp6 0 0 :::80 :::* LISTEN 96339/httpd [root@server3 httpd-2.4.29]# systemctl restart httpd.service
修改最大缓存时间为40s
三:Apache防盗链服务
3.1:什么是防盗链
3.2:环境介绍
IP地址
域名
用途
192.168.158.30
www.
服务器
192.168.158.10
www
盗链网站
客户端
Windows 10
客户机
3.3:模仿盗链过程
[root@server1 html]# cat index.html <html><body><h1>apache</h1><img src="https://192.168.158.30/20201013120035500.png"/></body></html>
图片不在本地3.4:主机开启防盗链功能
[root@server3 htdocs]# vi /etc/httpd.conf LoadModule rewrite_module modules/mod_rewrite.so #去注释
3.5:修改配置文件
#再合适位置添加以下内容 RewriteEngine On RewriteCond %{HTTP_REFERER} !^http://192.168.158.30$ [NC] RewriteCond %{HTTP_REFERER} !^http://192.168.158.30/* [NC] RewriteCond %{HTTP_REFERER} !^https://192.168.158.30/.*$ [NC] RewriteRule .*.(gif|png|swf)$ https://192.168.158.30/error.jpg [R,NC] #重写为网址的error图片
3.6:验证配置文件重启服务
[root@server3 htdocs]# httpd -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9a22:5aea:2642:6dff. Set the 'ServerName' directive globally to suppress this message Syntax OK [root@server3 htdocs]# apachectl -t AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9a22:5aea:2642:6dff. Set the 'ServerName' directive globally to suppress this message Syntax OK [root@server3 htdocs]# netstat -anpt | grep httpd tcp6 0 0 :::80 :::* LISTEN 110626/httpd
以上通过其他网站获取不到我服务器的资源四:隐藏版本信息
4.1:隐藏Apache版本信息作用
4.2:配置Apache隐藏版本信息
网站带来安全隐患生产环境中要配置Apache隐藏版本信息4.3:修改版本信息
[root@server3 conf]# pwd /usr/local/httpd/conf [root@server3 conf]# vi /etc/httpd.conf Include conf/extra/httpd-default.conf ##去注释 [root@server3 conf]# vi extra/httpd-default.conf ServerTokens Prod Serversignature Off
选项
输出格式
ServerTokens Prod
ServerTokens Major
ServerTokens Minor
Server:Apache/2.0
ServerTokens Min
Server:Apache/2.0.41
ServerTokens OS
Server: Apache/2.0.41 (Unix)
ServerTokens Full
Server: Apache/2.0.41 (Unix) PHP/4.2.2 MyMod/1.2
4.4:访问验证
五:本次实验所用图片
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算