一、自定义错误信息页面,并根据所请求的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)
一、前言
CMS中模板用置标嵌套头尾模板的方法,方便快捷,但是存在弊端,当文档数据量庞大时,只要嵌套的头尾模板稍有改动,就得完全发布站点才能更新所有的文档模板。数据量有几十万条,这个就是噩梦。使用SSI技术,将头尾作为独立文件嵌入到页面中,只要更新发布头尾文件就可以了。
二、Apache配置
Apache默认是不支持SSI的,更改httpd.conf来进行配置。
搜索“AddType text/html .shtml”,找到下面两行:
# AddType text/html .shtml
# AddOutputFilter INCLUDES .shtml
将这两行前面的#注释去掉。
搜索下面的默认页配置:
DirectoryIndex index.html index.htm
将index.shtml放到第一个位置
DirectoryIndex index.shtml index.html index.htm
接下来修改虚拟主机配置来支持shtml
例如下面的虚拟主机配置:
<VirtualHost *:80>
ServerAdmin webmaster@cas.cn
<Directory "/var/web/casweb/cas">
Options -Indexes FollowSymLinks Includes
Order allow,deny
Allow from all
</Directory>
DocumentRoot /var/web/casweb/cas/
ServerName www.cas.cn
ErrorLog logs/www.cas.cn-error_log
TransferLog "|/usr/local/sbin/cronolog /usr/local/apache2/logs/www.cas.cn-%Y%m%d-access_log"
</VirtualHost>
蓝色的Includes是在原来的基础上增加的。
三、SSI页面调用方法
用法:
<!--#include virtual="index.shtml" -->
include路径不能跨域,只能使用相对路径。
将上述代码插入到模板代码中,并将模板扩展名改为shtml
链接的文件名可以使用置标来获取,但必须指定具体的文件名,如index.shtml
在YSlow性能分析的第一条标准就是“Make fewer HTTP requests”。网站的响应时间大部分花费在前端,浏览器从服务器下载images、js 、flash等文件。在保持内容不变的情况下,首要做的就是减少浏览器请求文件的数量,网页中每个图标文件都需要发生一次请求。http协议是建立在请求/响应模式下的,浏览器发送请求信息(包括请求方法、URI、版本号等客户端信息)给服务器,服务器返回状态码,服务器信息、实体内容等。整个过程应该是首先浏览器和服务器先建立一个socket连接,然后客户端发送请求、服务器响应,关闭连接。默认情况是一个socket连接只能发生一次请求。那样的话,要打开一个网页,就可能重复上面的(连接、请求、响应、关闭连接)的过程N次,非常耗时。所以,在WEB服务器上可以进行配置可以使socket连接在一定时间内允许进行多个请求。例如,apache中的KeepAlive 设置为On时就可以。
在这基础上,再减少资源的数目,方法是将资源合并。CSS文件尽量外连,并合并到一个.css文件中,不同的用途之间可以用注释分隔符隔开区分。js文件同样是,图片可以采用CSS Sprites方法将小图合并到一张大图中,利用css定位,根据需要显示大图中的部分图像。例如,下面的导航菜单,当鼠标移动到菜单项,会显示不同的颜色的图片,而当前页又会显示另外一个颜色的图片。传统做法是做三个不同状态的图片,配合js切换。
按照CSS Sprites方法,三个状态图片合并到一张图:
常态下,只显示上面的图片,当鼠标hover的时候,样式如下
li a:hover span {background-position: 0 -26px; border-bottom-color: #5f5f5f;}
图像的Y轴坐标上移26px(每个小图的高度正好是26px),显示的是中间的图。当前页的时候,显示下面图:
li.selected a:hover span {background-position: bottom left;}
图像的处理还有一种就是maps,在一张大图上,做热区连接,但是不推荐。
本节只有CSS Sprites有些技术含量,其他的应该是工作习惯。
在FireFox下发现对网站性能评分的好工具YSlow,可以根据网站进行13类别性能评分,等级A-F,A最好,F最差。YSlow下载网址:http://developer.yahoo.com/yslow/,在download按钮下面有个提示:Install Firebug first!,需要先安装Firebug,http://getfirebug.com/,安装完成后,可以在FireFox的状态栏右边,看到YSlow图标,点击后就在浏览器的下半部出现分析窗口。点击上面的Performance,开始对当前网页进行性能分析,给出如下的13项得分:
下面是各项性能的评分:
阅读全文…
最新评论