Submitted by admin on 2012, July 19, 4:33 PM
ngx_http_limit_zone_module
Limit Zone Limit simultaneous connections from a client.
本模块可以针对条件,进行会话的并发连接数控制。(例如:限制每个IP的并发连接数。)
__配置示例__
http { : limit_zone   one  $binary_remote_addr  10m;  : ...  : server {  : ...  : location /download/ { : limit_conn   one  1; : }
指令
    - [#limit_zone limit_zone]
 
    - [#limit_conn limit_conn]
 
 
limit_zone
语法: limit_zone zone_name $variable the_size
默认值: no
作用域: http
本指令定义了一个数据区,里面记录会话状态信息。
$variable 定义判断会话的变量;the_size 定义记录区的总容量。
例子:
limit_zone   one  $binary_remote_addr  10m;
定义一个叫“one”的记录区,总容量为 10M,以变量 $binary_remote_addr 作为会话的判断基准(即一个地址一个会话)。
您可以注意到了,在这里使用的是 $binary_remote_addr 而不是 $remote_addr。
$remote_addr 的长度为 7 至 15 bytes,会话信息的长度为 32 或 64 bytes。而 $binary_remote_addr 的长度为 4 bytes,会话信息的长度为 32 bytes。
当区的大小为 1M 的时候,大约可以记录 32000 个会话信息(一个会话占用 32 bytes)。
 
limit_conn
语法: limit_conn zone_name the_size
默认值: no
作用域: http, server, location
指定一个会话最大的并发连接数。当超过指定的最发并发连接数时,服务器将返回 "Service unavailable" (503)。
例子:
limit_zone   one  $binary_remote_addr  10m;  : server { : location /download/ { : limit_conn   one  1; : }
定义一个叫“one”的记录区,总容量为 10M,以变量 $binary_remote_addr 作为会话的判断基准(即一个地址一个会话)。限制 /download/ 目录下,一个会话只能进行一个连接。简单点,就是限制 /download/ 目录下,一个IP只能发起一个连接,多过一个,一律503。
原文:http://wiki.nginx.org/ChsHttpLimitZoneModule
 
nginx | 评论:0
 | Trackbacks:0
 | 阅读:1142
Submitted by admin on 2012, July 17, 9:06 AM
    
        
            server 
            {  
            listen 205.105.100.110:80; 
            server_name www.baidu.net baidu.net; 
            sub_filter  'baidu.com'  'baidu.net'; 
            sub_filter_once on; 
             
             
            location / {  
            subs_filter_types text/html text/css text/xml text/javascript; 
            subs_filter baidu.com baidu.net; 
            proxy_set_header X-Real-IP $remote_addr;  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
            proxy_set_header Referer http://www.baidu.com[/url]; #强制定义Referer,程序验证判断会用到  
            proxy_set_header Host www.baidu.com; #定义主机头,如果目标站点绑定的域名个server_name项的吻合则使用$host  
            proxy_pass http://www.baidu.com; #指定目标,建议使用IP或者nginx自定义池  
            proxy_redirect http://www.baidu.com [url]http://www.baidu.net;  
            proxy_set_header Accept-Encoding ""; #清除编码  
            }  
            } | 
        
    
 
nginx | 评论:0
 | Trackbacks:0
 | 阅读:891
Submitted by admin on 2012, July 14, 4:38 PM
Apache启用gzip/deflate或者Nginx启用gzip之后
用wget测试的话需要加上--header="accept-encoding:gzip"
用curl则加上--compressed or -H Accept-Encoding:gzip,defalte
关于gzip和deflate有两篇文章
http://blog.fulin.org/2009/01/deflate_and_gzip.html
http://blog.developers.api.sina.com.cn/?p=266
 
 
 
linux | 评论:0
 | Trackbacks:0
 | 阅读:966
Submitted by admin on 2012, July 13, 3:57 PM
vsftpd yum 安装,使用系统帐号
pam_service_name=vsftpd
 
ftp | 评论:0
 | Trackbacks:0
 | 阅读:989
Submitted by admin on 2012, July 12, 6:24 PM
linux | 评论:0
 | Trackbacks:0
 | 阅读:944
Submitted by admin on 2012, July 9, 6:34 PM
为了抵制客户端恶意攻击,我们常使用mysql::real_escape_string()(等同于mysql_real_escape_string())函数过滤数据,但这个函数需要连接数据库,感觉有些不爽!
能不能再不用连接数据库的情况下,对用户输入的数据进行类似的过滤呢?你也许会想到addslashes()和mysql_escape_string()这两个函数,但这两个函数还是不如real_escape_string()的功能那么完美,具体区别就不说了,这里抄来一个功能相仿的函数,给大家琢磨探讨。
[code language=php]
function my_real_escape_string(str)
{
    return strtr($str, array(
        "\x00" => '\x00',
        "\n" => '\n',
        "\r" => '\r',
        '\\' => '\\\\',
        "'" => "\'",
        '"' => '\"',
        "\x1a" => '\x1a'
    ));
}
[/code]
 
php | 评论:0
 | Trackbacks:0
 | 阅读:985
Submitted by admin on 2012, July 9, 1:20 AM
INFO: task blocked for more than 120 seconds.
This is a know bug. By default Linux uses up to 40% of the available memory for file system caching. After this mark has been reached the file system flushes all outstanding data to disk causing all following IOs going synchronous. For flushing out this data to disk this there is a time limit of 120 seconds by default. In the case here the IO subsystem is not fast enough to flush the data withing 120 seconds. This especially happens on systems with a lof of memory.
The problem is solved in later kernels and there is not “fix” from Oracle. I fixed this by lowering the mark for flushing the cache from 40% to 10% by setting “vm.dirty_ratio=10″ in /etc/sysctl.conf. This setting does not influence overall database performance since you hopefully use Direct IO and bypass the file system cache completely.
原理:linux会设置40%的可用内存用来做系统cache,当flush数据时这40%内存中的数据由于和IO同步问题导致超时(120s),所将40%减小到10%,避免超时。
简单讲就是设置在文件 /etc/sysctl.conf中加入 “vm.dirty_ratio=10″ 。
 
linux | 评论:0
 | Trackbacks:0
 | 阅读:974
Submitted by admin on 2012, July 3, 9:24 AM
range_offset_limit这个参数,主要是对各种流媒体和要断点续传的文件的缓存的.缺省是0,也就是说只要client发过来的http header里包含了“Range:” ,squid会把这个请求转到后端http server,最致命的是,http server返回的内容并不会进入squid的cache store.
range_offset_limit就派上用场了,把它的值设置为-1;然后squid会把Range头去掉,而从后端http server把内容全部抓下来,放到cache store里,随后的对该cache的访问就不再转发到后端http server,可以大大提高命中率.也可以给这个参数设置一个值,会提前下载多少内容.但要注意,这个参数不要大过maximum_object_size ,不然下载完了,maximum_object_size 这个参数不能缓存这么多,又删除这个文件.白白点用你的流量.
 
squid/缓存 | 评论:0
 | Trackbacks:0
 | 阅读:1282