Welcome! Log In Create A New Profile

Advanced

Re: limit_rate based on proxy upstream response header

Maxim Dounin
January 05, 2010 07:50AM
Hello!

On Tue, Jan 05, 2010 at 01:54:19PM +1100, Robert Mueller wrote:

> We're using nginx as a proxy, and I want to limit the download rate of
> certain proxied pages/files depending on a header potentially set by the
> backend server. I'm trying something like:
>
> location ^~ / {
> set $slowrate $upstream_http_x_rate_limit;
> if ($slowrate) {
> set $limit_rate $slowrate;
> }
>
> rewrite (.*) /http/$host$1 break;
>
> proxy_pass http://backend/;
> proxy_hide_header X-Rate-Limit;
> ...
> }
>
> And then setting the X-Rate-Limit header on the backend response, but
> that doesn't seem to work.
>
> So I tried even simpler, allowing just a simple "make this slow" header
> setting.
>
> location ^~ / {
> set $slowrate $upstream_http_x_rate_limit;
> if ($slowrate) {
> limit_rate 100;
> }
>
> rewrite (.*) /http/$host$1 break;
>
> proxy_pass http://backend/;
> proxy_hide_header X-Rate-Limit;
> ...
> }
>
> Yes, I really wanted to try just 100 bytes/second. But that didn't work
> either.

It's expected, as rewrite directives (including "set" and "if")
are exectured during rewrite phase, i.e. before request to backend
happens.

> Is there a way of doing this?

Try returning X-Accel-Limit-Rate header instead. Not sure it's
documented somewhere except in source code, but it's at least
mentioned here:

http://wiki.nginx.org/NginxXSendfile

Maxim Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

limit_rate based on proxy upstream response header

Robert Mueller January 04, 2010 09:58PM

Re: limit_rate based on proxy upstream response header

Maxim Dounin January 05, 2010 07:50AM

Re: limit_rate based on proxy upstream response header

Rob Mueller January 05, 2010 06:22PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 149
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready