Apache 及开启压缩及Header信息隐藏

      昨天老大说:“看一个网站的管理员专业不专业就看header返回的信息”,当时我一头雾水。原来当客户端连接到Apache服务器的时候,Apache一般会返回服务器版本、非缺省模块等信息,会被黑客利用,例如:


  
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

转载于:https://my.oschina.net/subone/blog/702705

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值