一、自定义错误信息页面,并根据所请求的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
将apache日志按年月日目录分类存放,便于日志分析系统分析。使用cronolog来完成,有windows和linux的版本。Linux安装,解压缩后执行
#./configure
#./make
#./make install
在httpd.conf配置使用cronolog,在每个虚拟主机中,加入
CustomLog "|/usr/local/sbin/cronolog /var/logs/%Y/%m/%Y%m%d_access.log" combined
ErrorLog "|/usr/local/sbin/cronolog /var/logs/%Y/%m/%Y%m%d_error.log"
Windows下cronolog安装,解压缩后,将cronolog.exe文件放到apache安装目录的bin下。配置httpd.conf
TransferLog "|D:/Apache/bin/cronolog.exe D:/Apache/logs/%Y/%m/%d/access.log"
ErrorLog "|D:/Apache/bin/cronolog.exe D:/Apache/logs/%Y/%m/%d/access.log"
1、Apache2.2.9的安装只用了一个配置命令:
./configure –prefix=/usr/local/apache –enable-rewrite=shared
2、Tomcat5.5.16二进制方式,解压。
3、安装jakarta-tomcat-connectors-jk2-src-current.tar.gz
下载地址:http://archive.apache.org/dist/jakarta/tomcat-connectors/jk2/source/
解压后,进入到jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2目录
执行./configure –with-apxs2=/usr/local/apache/bin/apxs
make
拷贝mod_jk2.so文件,到apache的modules目录。
cp jakarta-tomcat-connectors-jk2-2.0.4-src/jk/build/jk2/apache2/mod_jk2.so
/usr/local/apache/modules/
4、配置apache配置文件:
编辑httpd.conf
Listen 10.10.10.197:80下面添加一行,加载mod_jk2.so.
LoadModule jk2_module modules/mod_jk2.so
找到下面一行,并且去掉注释符号#,加载虚拟主机配置文件
Include conf/extra/httpd-vhosts.conf
5、配置虚拟主机:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <VirtualHost *>
ServerAdmin web@domain.com
DocumentRoot "/usr/local/tomcat/webapps"
#需要转给tomcat处理的文件名,如*.jsp,这里是*.*所有文件处理转给tomcat
<Location ~ "/*.*">
JkUriSet worker ajp13:localhost:8009
</Location>
ServerName search.domain.com
ErrorLog "logs/search-error_log"
CustomLog "logs/search-access_log" common
#定义虚拟主机目录属性,新版本的apache必须要加这段,否则无法指定默认根目录之外的目录
<Directory "/usr/local/tomcat/webapps">
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost> |
背景:
我们公司的web服务器是linux+apache,自己有一个内部交流的OA放在web服务器上,同时还有一些外部的网站。其中内部的OA除了公司的人其他人是不允许访问的。仅依靠OA系统本身的登陆验证不够。需要对整个OA程序从文件角度验证。这就利用apache身份验证。
采用“用户名+密码”以文本文件为存储方式的认证。
方法:
一、修改apache的配置文件。
阅读全文…
最新评论