全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
楼主: gdtv
打印 上一主题 下一主题

急救:nignx怎么对网站或者目录或者IP进行带宽限制?

[复制链接]
21#
 楼主| 发表于 2009-11-14 13:58:24 | 只看该作者
原帖由 cpuer 于 2009-11-14 13:01 发表
Limit_rate

语法:limit_rate speed

默认值:no

Context:http,server,location

用来限制服务器对客户的应答传输速率,速率是B/S,此限制仅对一个连接有效,如果客户发起两个连接,速率将会是高于限制的两倍。

服务器级别上限 ...


[emerg]: unknown "slow" variable
22#
发表于 2009-11-14 14:04:06 | 只看该作者

回复 24# 的帖子

看来还要在哪去定义下 $slow
23#
发表于 2009-11-14 14:33:32 | 只看该作者
ngx_http_limit_zone_module
这个模块是限制并发连接数的
不能真正的起到限速的作用 只是变相的 限制连接数从而减少带宽 或者采集
24#
发表于 2009-11-14 14:34:39 | 只看该作者
原帖由 gdtv 于 2009-11-14 13:14 发表
limit_conn   one 1; 这个很不好用,多于一个连接,不是等待、然后依次连接,而是直接Kill掉。
所以如果一个页面有多个图片,只能显示一个了


对的 呵呵 这个 对于下载有用处 图片站 不建议开启
25#
发表于 2009-11-14 14:46:57 | 只看该作者
原帖由 zyypp 于 2009-11-14 14:33 发表
ngx_http_limit_zone_module
这个模块是限制并发连接数的
不能真正的起到限速的作用 只是变相的 限制连接数从而减少带宽 或者采集


是的,最好把图片访问专门的服务器,不会影响web页面打开。
26#
 楼主| 发表于 2009-11-14 14:51:46 | 只看该作者
原帖由 zyypp 于 2009-11-14 14:33 发表
ngx_http_limit_zone_module
这个模块是限制并发连接数的
不能真正的起到限速的作用 只是变相的 限制连接数从而减少带宽 或者采集


现在还没解决
1、如果用limit_conn,那么多余的图片会显示X,而不是排列等待下载
2、如果用limit_rate,那么空闲的时候limit_rate不能自动调整,浪费
现在只有寄望于if($slow){set $limit_rate 4k;},可是不知这个怎么弄。
27#
发表于 2009-11-14 15:00:58 | 只看该作者

回复 29# 的帖子

如果你限制速度的话打开那个网站速度会很慢的。
28#
发表于 2009-11-14 15:08:46 | 只看该作者
原帖由 gdtv 于 2009-11-14 13:58 发表
[emerg]: unknown "slow" variable


看下nginx.conf server段配置详情。

直接写 limit_rate 8k; 不用判断看看。
29#
发表于 2009-11-14 15:31:28 | 只看该作者
原帖由 gdtv 于 2009-11-14 14:51 发表


现在还没解决
1、如果用limit_conn,那么多余的图片会显示X,而不是排列等待下载
2、如果用limit_rate,那么空闲的时候limit_rate不能自动调整,浪费
现在只有寄望于if($slow){set $limit_rate 4k;},可是不知这个怎么弄。 ...


limit_conn 是限制并发数的 就像是IIS的连接限制一样 超过了限制就是返回503之类
limit_rate 具体你可以看http://wiki.nginx.org/NginxHttpCoreModule然后查询 limit_rate  我贴一边
limit_rate
syntax: limit_rate speed

default: no

context: http, server, location, if in location

Directive assigns the speed of transmission of the answer to client. Speed is assigned in the bytes per second. Limitation works only for one connection, i.e., if client opens 2 connections, then total velocity will be 2 times higher then the limit set.

If it is necessary to limit speed for the part of the clients at the server level, based on some kind of condition - then this directive does not apply. Instead you should specify the limit by assigning the value to the $limit_rate variable, as shown below:
  1. server {
  2.   if ($slow) {
  3.     set $limit_rate  4k;
  4.   }
  5. }
复制代码
limit_rate_after
syntax: limit_rate_after time

default: limit_rate_after 1m

context: http, server, location, if in location

The directive limits speed only after the first part was sent.
  1. limit_rate_after 1m;
  2. limit_rate 100k;
复制代码


不过我以前对以下载试过 在location中limit_rate无效(内网测试)
server {
  if ($slow) {
    set $limit_rate  4k;
  }
}
这个我没试验过 呵呵
30#
发表于 2009-11-14 15:51:13 | 只看该作者

回复 32# 的帖子

location 有很多人说过无效,只能放server段里面,

limit_rate 10k;

这样就行了吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2026-1-13 14:06 , Processed in 0.059395 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表