Rails App, Nginx, Virtual Hosts and bandwidth shaping


#1

Hi,
I’m testing a Rails app that serves multiple different sites with a
virtual hosts configuration under nginx. I need to set a limit
per host basis so a single site will be unable to eat all the bandwidth
and
server resources. Nginx can limit per ip but not per vhost, right?

Any solution?
Thank you in advance :slight_smile:

d.


#2

Daniele :slight_smile: wrote:

Hi,
I’m testing a Rails app that serves multiple different sites with a
virtual hosts configuration under nginx. I need to set a limit
per host basis so a single site will be unable to eat all the bandwidth
and
server resources. Nginx can limit per ip but not per vhost, right?

Any solution?
Thank you in advance :slight_smile:

nginx currently can limit bandwidth only on per-connection basis.

But we can limit rate for each connection, and than limit maximum number
of connection to each
virtual host.

Somethings like:

http {
limit_rate 250000;
limit_zone conn_to_server $server_name 10m;

limit_conn conn_to_server 100;

server { … }
server { … }
server { … }
}

With this settings each virtualhost can’t use more than 250000*100 = 25
Mbit of bandwidth.


#3

Anton Y. wrote:

With this settings each virtualhost can’t use more than 250000*100 = 25
Mbit of bandwidth.

Wonderful, thank you very much Anton!

Is it possibile to find out when the limit is triggered? I read that
this setup generate a Service unavailable (503), I suppose it’s logged
so I can parse the file and fire and alert. Other solutions?

By the way I will prefer a solution that slow down all the requests (I
really dont know how, queue? throttle?) instead of killing them. Is it
possibile?