一、自定义错误信息页面,并根据所请求的URL所在的域,跳转到所在域名。
二、自定义APACHE错误信息,指定错误信息页面。配置文件里面有例子信息,去掉下面的注释符号#,激活。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| Alias /error/ "/usr/local/apache2/error/"
<Directory "/usr/local/apache2/error">
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en cs de es fr it ja ko nl pl pt-br ro sv tr
ForceLanguagePriority Prefer Fallback
</Directory>
ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
ErrorDocument 404 /error/404/index.html
ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
ErrorDocument 410 /error/HTTP_GONE.html.var
ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var |
三、实现跳转JS。
新建错误信息html页面,页面中关键代码如下:
1
| 页面没有找到,将在<SPAN id=return_page>5</SPAN>秒钟后带您返回网站首页 ! |
倒计时5秒后,跳转页面。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
var ym=document.domain;//获取请求的URL域名+++ 关键 ++++
var returnid=5;
function return_prepage(){
document.getElementById("return_page").innerHTML=returnid+"";
if(returnid==0){
window.location.href="http://"+ym; //重定向到请求的域名网站
}
returnid=returnid-1;
if(returnid>-1){
window.setTimeout("return_prepage()",1000);}
}
return_prepage(); |
首先查看apache是否加载了mod_deflate.so模块,如果没有需要安装加载。
找到并下载和当前apache版本相同的源码文件,解压缩到/home目录下,
在apache安装目录下执行:
/usr/local/apache2/bin/apxs -i -c /home/httpd-2.0.63/modules/filters/mod_deflate.c
会自动在 httpd.conf添加
LoadModule deflate_module modules/mod_deflate.so
添加如下设置:
<IfModule mod_deflate.c>
<Location />
#Insert filter
SetOutputFilter DEFLATE
# 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
# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.59
# the above regex won’t work. You can use the following
# workaround to get the desired effect:
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html force-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don’t compress images and other
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|doc)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary
#DeflateFilterNote ratio ratio_info
#LogFormat '"%v %h %l %u %t “%r" %>s %b "%{Referer}i" "%{User-Agent}i"" (%{ratio}n)' deflate
#CustomLog logs/deflate_log deflate
</Location>
</IfModule>
停止apache服务./apachectl stop,报错如下:
Cannot load /usr/local/apache2/modules/mod_deflate.so into server: /usr/local/apache2/modules/mod_deflate.so: undefined symbol: deflate解决如下:
vi /usr/local/apache2/bin/apr-config
修改LDFLAGS=" " 为 LDFLAGS="-lz"
停止启动服务:仍提示:
DeflateFilterNote not allowed here
CustomLog not allowed here
注释掉后,正常。
对 web服务器进行安全性端口扫描,发现一些问题,apache加以调整:
1、HTTP TRACE method
需要关闭HTTP TRACE 方法,检测apache是否打开了trace方法,使用如下方法:
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
TRACE / HTTP/1.0
Host: foo
然后按两次回车,出现下面的信息,证明方法激活了。
HTTP/1.1 200 OK
Date: Sat, 20 Oct 2007 20:39:36 GMT
Server: Apache/2.2.6 (Debian)
Connection: close
Content-Type: message/http
TRACE / HTTP/1.0
Host: foo
否则会出现:
HTTP/1.1 403 Forbidden
等信息。
解决方法:修改httpd.conf,修改如下数值:TraceEnable Off
2、隐藏apache版本等信息:
访问一个不存在的页面,apache会报如下错误:
Not Found
The requested URL /ss.c was not found on this server.
———————–
Apache/2.0.63 (Unix) DAV/2 mod_jk/1.2.20 Server at ip Port 80
错误信息中包含apache的版本和使用的操作系统等.
解决办法:修改httpd.conf:
设置如下数值:
ServerTokens Prod(默认为Full)
ServerSignature Off(默认为On)
最新评论