如何设 置请求等待时间 在httpd.conf里面设置: timeout n 其中n为整数,单位是秒。 如何接收一个get请求的总时间 接收一个post和put请求的tcp包之间的时间 tcp包传输中的响应(ack)时间间隔 如何使得apache监听在特定的端口 修改httpd.conf里面关于listen
++如何设 置请求等待时间
在httpd.conf里面设置:
timeout n
其中n为整数,单位是秒。
++如何接收一个get请求的总时间
接收一个post和put请求的tcp包之间的时间
tcp包传输中的响应(ack)时间间隔
++如何使得apache监听在特定的端口
修改httpd.conf里面关于listen的选项,例如:
listen 8000
是使apache监听在8000端口
而如果要同时指定监听端口和监听地址,可以使用:
listen 192.170.2.1:80
listen 192.170.2.5:8000
这样就使得apache同时监听在192.170.2.1的80端口和192.170.2.5的8000端口。
当然也可以在httpd.conf里面设置:
port 80
这样来实现类似的效果。
++如何设置apache的最大空闲进程数
修改httpd.conf,在里面设置:
maxspareservers n
其中n是一个整数。这样当空闲进程超过n的时候,apache主进程会杀掉多余的空闲进程而保持空闲进程在n,节省了系统资源。如果在一个apache非常繁忙的站点调节这个参数才是必要的,但是在任何时候把这个参数调到很大都不是一个好主意。
同时也可以设置:
minspareservers n
来限制最少空闲进程数目来加快反应速度。
++apache如何设置启动时的子服务进程个数
在httpd.conf里面设置:
startservers 5
这样启动apache后就有5个空闲子进程等待接受请求。
也可以参考minspareservers和maxspareservers设置。
++如何在apache中设置每个连接的最大请求数
在httpd.conf里面设置:
maxkeepaliverequests 100
这样就能保证在一个连接中,如果同时请求数达到100就不再响应这个连接的新请求,保证了系统资源不会被某个连接大量占用。但是在实际配置中要求尽量把这个数值调高来获得较高的系统性能。
#用户连续访问了多少个页面后重新建立联结,适当调高.
++如何在apache中设置session的持续时间
在apache1.2以上的版本中,可以在httpd.conf里面设置:
keepalive on
keepalivetimeout 15
这样就能限制每个session的保持时间是15秒。session的使用可以使得很多请求都可以通过同一个tcp连接来发送,节约了网络资源和系统资源。
#keepalivetimeout是允许用户保持连接15秒内有效,如果用户在15秒内点击其他页面不需要重新建立联结,这个值设置短不利于降低效率,如果设置长可能导致的同时联结数会跟高,一般建议按照缺省的15
++如何使得apache对客户端进行域名验证
可以在httpd.conf里面设置:
hostnamelookups on|off|double
如果是使用on,那么只有进行一次反查,如果用double,那么进行反查之后还要进行一次正向解析,只有两次的结果互相符合才行,而off就是不进行域名验证。
如果为了安全,建议使用double;为了加快访问速度,建议使用off。
++如何使得apache只监听在特定的ip
修改httpd.conf,在里面使用
bindaddress 192.168.0.1
这样就能使得apache只监听外界对192.168.0.1的http请求。如果使用:
bindaddress *
就表明apache监听所有网络接口上的http请求。
当然用防火墙也可以实现。
++apache中如何限制http请求的消息主体的大小
在httpd.conf里面设置:
limitrequestbody n
n是整数,单位是byte。
cgi脚本一般把表单里面内容作为消息的主体提交给服务器处理,所以现在消息主体的大小在使用cgi的时候很有用。比如使用cgi来上传文件,如果有设置:
limitrequestbody 102400
那么上传文件超过100k的时候就会报错。
++如何修改apache的文档根目录
修改httpd.conf里面的documentroot选项到指定的目录,比如:
documentroot /www/htdocs
这样http://localhost/index.html就是对应/www/htdocs/index.html
++如何修改apache的最大连接数
在httpd.conf中设置:
maxclients n
n是整数,表示最大连接数,取值范围在1和256之间,如果要让apache支持更多的连接数,那么需要修改源码中的httpd.h文件,把定义的hard_server_limit值改大然后再编译。
++如何使每个用户有独立的cgi-bin目录
有两种可选择的方法:
(1)在apache配置文件里面关于public_html的设置后面加入下面的属性:
scriptaliasmatch ^/~([^/]*)/cgi-bin/(.*) /home/$1/cgi-bin/$2
(2)在apache配置文件里面关于public_html的设置里面加入下面的属性:
options execcgi
sethandler cgi-script
++如何调整apache的最大进程数
apache允许为请求开的最大进程数是256,maxclients的限制是256.如果用户多了,用户就只能看到waiting for
reply….然后等到下一个可用进程的出现。这个最大数,是apache的程序决定的–它的nt版可以有1024,但unix版只有256,你可以在src/include/httpd.h中看到:
#ifndef hard_server_limit
#ifdef win32
#define hard_server_limit 1024
#else
#define hard_server_limit 256
#endif
#endif
你可以把它调到1024,然后再编译你的系统。
++如何屏蔽来自某个internet地址的用户访问apache服务器
可以使用deny和allow来限制访问,比如要禁止202.202.202.xx网络的用户访问:
order deny,allow
deny from 202.202.202.0/24
++如何在日志里面记录apache浏览器和引用信息
你需要把mod_log_config编译到你的apache服务器中,然后使用下面类似的配置:
customlog logs/access_log “%h %l %u %t “%r” %s %b “%{referer}i”
“%{user-agent}i”
++如何修改apache返回的头部信息
问题分析:当客户端连接到apache服务器的时候,apache一般会返回服务器版本、非缺省模块等信息,例如:
server: apache/1.3.26 (unix) mod_perl/1.26
解决:
你可以在apache的配置文件里面作如下设置让它返回的关于服务器的信息减少到最少:
servertokens prod
注意:
这样设置以后apache还会返回一定的服务器信息,比如:
server: apache
但是这个不会对服务器安全产生太多的影响,因为很多扫描软件是扫描的时候是不顾你服务器返回的头部信息的。你如果想把服务器返回的相关信息变成:
server: it is a none-apache server
那么你就要去修改源码了。
++ 产生日志但不包括 图片。
logformat “%h %l %u %t \”%r\” %>;s %b \”%{referer}i\” \”%{user-agent}i\” combined
setenvif request_uri \.gif$ gif-image
setenvif request_uri \.gif$ gif-image
setenvif request_uri \.jpg$ gif-image
setenvif request_uri \.jpg$ gif-image
setenvif request_uri \.png$ gif-image
setenvif request_uri \.swf$ gif-image
setenvif request_uri \.swf$ gif-image
setenvif request_uri \.css$ gif-image
setenvif request_uri \.css$ gif-image
setenvif request_uri \.js$ gif-image
setenvif request_uri \.js$ gif-image
setenvif request_uri \.ico$ gif-image
;
serveradmin webmaster@abc.net
documentroot /db/htdocs/www
servername www.abc.net
customlog “|/usr/local/cronolog/sbin/cronolog /db/logs/www.%y-%m-%d.log” combined env=!gif-image
#用cronolog截取存放在/db/logs/下的按日期产生的apache日志文件,不包括图片
;
另一方法:
setenv imag 1
customlog logs/access_log combined env=!imag
++首先拒绝任何人,然后允许来自特定主机的访问。
order deny,allow
deny from all
allow from dev.example.com
++将/xyz/old.html的请求重写为物理的文件/website/test1/abc/new.html
1).在httpd.conf中有’alias /xyz /website/test1/abc’这条指令
2).在/website/test1/abc/下建立.htaccess文件,内容如下
rewriteengine on
rewritebase /xyz
rewriterule ^old\.html$ new.html
3).为了保证启用.htaccess,需要在httpd.conf中配置
allowoverride all
#注: rewritebase指令显式地设置了目录级重写的基准url。
++根据浏览器类型决定返回什么网页文件
rewriteengine on
rewritecond %{http_user_agent} ^mozilla.*
rewriterule ^/$ /homepage.max.html [l]
#其它类推
++rewrite其它
rewriteengine on
rewriteloglevel 3 #较高的值会使apache速度急剧下降! 重写日志使用大于2的level值只用于调试!
rewritelog “/usr/local/var/apache/logs/rewrite.log” #写log
rewriterule ^/$ /film/index.shtml [r,l] # 重定向首页到另一个文件
rewriterule ^/$ /film/index.shtml [p,l] # 重定向首页到另一个文件,同时不改url地址名
++关闭错误文档的最后一行将包含服务器的名字、apache的版本等信息
serversignature off #默认值为on,也可改为serversignature email ,这样将显示管理员的email地址
++将以/puppy及/puppies开头的url对应至/www/docs/small_dogs目录
aliasmatch ^/pupp(y|ies) /www/docs/small_dogs
++redirect指令将特定url重定向至其它的服务器上
redirect [关键字] /example http://www.otherserver.com/new/location
关键字:
temp — 临时的重定向,返302状态响应,客户端会记往原始请求所用的url
permanent — 永久性的重定向,返301响应,客户端会记得新的url
gone — 告之用户,此url已被移除了,而且不会再回来了, 这个关键字后不需要跟新url参数,返410状态.
seeother — 告之客户端旧的url已经被废弃了,但文件的内容已经被新文件的内容取代了返303状态.
++将多个url重定向至同一位置
redirectmatch ^/[ff]ish(ing)? http://fis.example.com
++接受不区分大小写的url
checkspelling on #mod_speling模块支持
++将请求url中所有的string1都改为string2
rewritecond %{request_uri} “string1″
rewriterule “(.*)string1(.*)” “$1string2$2″ [n,pt]
#[n]标记让apache不断重复执行重写的规则,直至rewritecond条件失效为止.
++手工安装某模块(以rewrite为例)
/usr/local/apache/bin/apxs -c mod_rewrite.c ##apxs应指定绝对路径
/usr/local/apache/bin/apxs -i -a -n mod_rewrite mod_rewrite.la
#编辑httpd.conf文件
loadmodule rewrite_module modules/mod_rewrite.so
++一个虚拟主机的例子
namevirtualhost *:80
serveradmin webmaster@zhangjianfeng.com
servername blog.zhangjianfeng.com
serveralias web1.zhangjianfeng.com
documentroot “/web/web1/”
errorlog /logs/apache/web1_error_log
customlog /logs/apache/web1_log combined
rewriteengine on
#rewriteloglevel 1
#rewritelog “/logs/apache/rewrite.log”
#rewriterule \.(exe|rar)$ http://downloads.zhangjianfeng.com/data/$1 [r]
++servertokens指令
servertokens major|minor|min[imal]|prod[uctonly]|os|full
servertokens prod[uctonly] 服务器会发送(比如): server: apache
servertokens major 服务器会发送(比如): server: apache/2
servertokens minor 服务器会发送(比如): server: apache/2.0
servertokens min[imal] 服务器会发送(比如): server: apache/2.0.41
servertokens os 服务器会发送(比如): server: apache/2.0.41 (unix)
servertokens full (或未指定) 服务器会发送(比如): server: apache/2.0.41 (unix) php/4.2.2 mymod/1.2
++其它
order allow,deny
deny from all
user apache
group apache
serveradmin root@zhangjianfeng.com
servername websrv1
usecanonicalname off
hostnamelookups off
logformat “%h %l %u %t \”%r\” %>s %b \”%{referer}i\” \”%{user-agent}i\” combined
customlog logs/access_log combined
errorlog logs/error_log
serversignature on|off|email
servertokens major|minor|min[imal]|prod[uctonly]|os|full
++查看目前连接协议情况
netstat -an | grep -i “80″ | awk ‘{print $6}’ | sort | uniq -c | sort -n
++一个简单的密码认证实现
#添加下面内容到httpd.conf
alias /test2 “/var/www/html/test”
allowoverride authconfig
order deny,allow
allow from all
#建立验证文件和第一个验证用户
#htpasswd -c /etc/userfile user
#vi /var/www/html/test/usergroup
usergroup:user user1 user2 #相关用户使用htpasswd创建
#vi /var/www/html/test/.htaccess
authname “blog.zhangjianfeng.com user_auth test”
authtype basic
authuserfile /etc/userfile
#以下两行只有在以组的形式管理,才需要
#authgroupfile /var/www/html/test/usergroup
#require group usergroup
require user user
++手工get数据(用于测试等)
telnet blog.zhangjianfeng.com 80
escape character is ‘^]’.
get /index.php http/1.1
accept: text/plain,text/html,*/*;q=0.3
accept-encoding: deflate
host: http://www.test.com:8004/
if-none-match: “418112890:855172144000″
user-agent: w3crobot/5.1 libwww/5.1
connection: keep-alive
++取http head
curl –head http://blog.zhangjianfeng.com/
++为apache配置mod_deflat压缩输出
loadmodule deflate_module modules/mod_deflate.so
loadmodule headers_module modules/mod_headers.so
deflatecompressionlevel 9
setoutputfilter deflate
#deflatefilternote input instream
#deflatefilternote output outstream
#deflatefilternote ratio ratio
logformat ‘”%r” %{outstream}n/%{instream}n (%{ratio}n%%)’ deflate
customlog logs/deflate_log.log deflate
#need more? http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
++mod_proxy应用, 将 www.zhangjianfeng.com/news 的请求转到另一台主机
loadmodule proxy_module modules/mod_proxy.so
proxypass /news http://news.zhangjianfeng.com/ #news.zhangjianfeng.com为另一台主机
