Apache 及开启压缩及Header信息隐藏
昨天老大说:“看一个网站的管理员专业不专业就看header返回的信息”,当时我一头雾水。原来当客户端连接到Apache服务器的时候,Apache一般会返回服务器版本、非缺省模块等信息,会被***利用,例如:[*]Connectionclose
[*]Content-Type text/html; charset=UTF-8
[*]Date Wed, 29 Feb 2012 07:51:08 GMT
[*]P3P CP="CAO PSA OUR"
[*]ServerApache/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
[*]
[*]
[*] 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 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
[*]
[*]#以下内容控制浏览器缓存时间及header信息,
[*]
[*] 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"
[*]
[*] #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
[*]
[*]
效果:
[*]Cache-Control private
[*]Connectionclose
[*]Content-Encoding gzip
[*]Content-Type text/html; charset=UTF-8
[*]Date Wed, 29 Feb 2012 07:04:23 GMT
[*]P3P CP="CAO PSA OUR"
[*]ServerFBS
[*]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
[*]
[*]
页:
[1]