Nginx – How to we restrict dynamically nginx upload/download speed per user

bandwidth-controlnginxPHP

It's possible to restrict the speed using the rate limit on a specific location.

However, how can we do it dynamically ?

Let say you have paid vs non-paid users and you want to give an higher bandwidth to paid users.

We would need to dynamically check in the Database and allow a certain speed for this particular group of users.

Do you have any nginx module in mind ?

Best Answer

Yes, you can rate limit on a specific location.

location /something/ { 
    set $limit_rate  4k; 
}

You can also surround the limite_rate with statements like if as well to dynamically control the rates. See this link for further details on limite rate: http://wiki.nginx.org/NginxHttpCoreModule#limit_rate

There is another module you should be mindful of: http://wiki.nginx.org/NginxHttpLimitZoneModule

That module allows you to set limits of connection count. So, even if you set a low limit, if they can just make 10 connections, your limit is rather meaningless.

I suggest you have private and public users get different links so that nginx can easily distinguish between the types of users and verify in your application layer for security.