Apache 及开启压缩及Header信息隐藏
2016-06-29 00:00
489 查看
昨天老大说:“看一个网站的管理员专业不专业就看header返回的信息”,当时我一头雾水。原来当客户端连接到Apache服务器的时候,Apache一般会返回服务器版本、非缺省模块等信息,会被黑客利用,例如:
注意:这样设置以后Apache还会返回一定的服务器信息,比如:
Server: Apache
但是这个不会对服务器安全产生太多的影响,因为很多扫描软件是扫描的时候是不顾你服务器返回的头部信息的。你如果想把服务器返回的相关信息变成百度的一样:
Server BWS/1.0
那么你就要去修改源码了。
具体方法如下:
一、修改Apache的几个源代码文件
二、重新编译apache,添加压缩模块
编辑httpd.conf加入如下内容
效果:
参考网址:
本文出自 “Centi.Linux” 博客,请务必保留此出处http://centilinux.blog.51cto.com/1454781/792820
Connection close Content-Type text/html; charset=UTF-8 Date Wed, 29 Feb 2012 07:51:08 GMT P3P CP="CAO PSA OUR" Server Apache/2.2.21 (Unix) Transfer-Encoding chunked X-Powered-By PHP/5.3.9 解决方法: 你可以在Apache的配置文件里面作如下设置让它返回的关于服务器的信息减少到最少: #修改httpd-default.conf 的如下内容,修改后header将取消X-Powered-By PHP/5.3.9的显示 ServerTokens Prod ServerSignature Off
注意:这样设置以后Apache还会返回一定的服务器信息,比如:
Server: Apache
但是这个不会对服务器安全产生太多的影响,因为很多扫描软件是扫描的时候是不顾你服务器返回的头部信息的。你如果想把服务器返回的相关信息变成百度的一样:
Server BWS/1.0
那么你就要去修改源码了。
具体方法如下:
一、修改Apache的几个源代码文件
修改: httpd-2.2.21/include/ap_release.h #define AP_SERVER_BASEVENDOR"这里填写开发组织名,例如:Microsoft Corp." #defineAP_SERVER_BASEPRODUCT"这里填写服务器软件名,例如:Microsoft-IIS" #defineAP_SERVER_MAJORVERSION "主版本,例如:5" #defineAP_SERVER_MINORVERSION "次版本,例如:0" #defineAP_SERVER_PATCHLEVEL "修正版本,例如:1" 修改: httpd-2.2.21/os/os2/os.h #define PLATFORM "这里填写操作系统的名称,例如:Win32"
二、重新编译apache,添加压缩模块
cd httpd-2.2.21 ./configure --prefix=/usr/local/apache --enable-so --enable-expires --enable-mime-magic --enable-threads --enable-rewrite --disable-env --disable-actions --disable-asis --disable-setenvif --disable-version --disable-userdir --disable-authz-groupfile --disable-authn-file --disable-authz-user --disable-include --disable-filter --disable-cgid --disable-cgi --enable-ssl --with-ssl --enable-setenvif --with-mpm=prefork --enable-headers=shared --enable-deflate=shared make&&make install
编辑httpd.conf加入如下内容
LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so <IfModule mod_deflate.c> SetOutputFilter DEFLATE #开启压缩 #不压缩的文件类型 SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary #要压缩的文件类型 AddOutputFilterByType DEFLATE text/* AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </IfModule> #以下内容控制浏览器缓存时间及header信息, <IfModule mod_expires.c> ExpiresActive on #浏览器缓存开启 #ExpiresDefault "access plus 1 month" #设置默认过期时间为1个月 #ExpiresByType text/html "access plus 1 months" #动态网站不推荐开启此项 ExpiresByType text/css "access plus 1 months" ExpiresByType image/gif "access plus 1 months" ExpiresByType image/x-icon "access plus 1 month" ExpiresByType image/jpeg "access plus 1 months" ExpiresByType image/jpg "access plus 1 months" ExpiresByType image/png "access plus 1 months" EXpiresByType application/x-shockwave-flash "access plus 1 months" EXpiresByType application/javascript "access plus 1 months" Header unset Pragma FileETag None Header unset ETag Header set Cache-Control "private" <FilesMatch "\.(js|css|ico|pdf|flv|jpg|jpeg|png|gif|mp3|mp4|swf)$"> #Header set Expires "Wen, 29 Feb 2012 14:14:00 GMT" #Header set Cache-Control must-revalidate,post-check=0,pre-check=0 Header unset Last-Modified </FilesMatch> </IfModule>
效果:
Cache-Control private Connection close Content-Encoding gzip Content-Type text/html; charset=UTF-8 Date Wed, 29 Feb 2012 07:04:23 GMT P3P CP="CAO PSA OUR" Server FBS Transfer-Encoding chunked Vary Accept-Encoding,User-Agent
参考网址:
http://yolcy.blog.163.com/blog/static/105307937201022471913971/ http://hi.baidu.com/%C8%FD%BE%D6%CE%AA%B6%FE/blog/item/30dae1325363ed92a8018e5c.html
本文出自 “Centi.Linux” 博客,请务必保留此出处http://centilinux.blog.51cto.com/1454781/792820
相关文章推荐
- Apache Isis 1.4.0 发布,领域驱动开发框架
- RH436 Day3 课后总结
- Linux快速构建apache web服务器
- Awstats处理多apache日志
- 安装perl模块小窍门
- Apache静态编译与动态编译的区别
- 如何在 Ubuntu Linux 中使用 RAR 文件
- PHP+Apache在Windows 9x下的安装和配置
- Apache服务器配置全攻略
- Apache Web让JSP“动”起来
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- apache 环境下 php 的配置注意事项
- C#使用DeflateStream解压缩数据文件的方法
- C# 利用ICSharpCode.SharpZipLib实现在线压缩和解压缩
- C#使用WinRar命令进行压缩和解压缩操作的实现方法
- C#调用WinRar执行rar、zip压缩的方法
- C语言压缩文件和用MD5算法校验文件完整性的实例教程
- 在RedHat下安装apache jserv 1.1.2方法
- windows8.1下Apache+Php+MySQL配置步骤