Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am starting a small web hosting company to teach me about system administration and one of the problems I am having is how would I limit the bandwidth and disk space of each virtual host (Debain/nginx)? Or am I going about it the wrong way and should not use virtual hosts?

share|improve this question

migrated from stackoverflow.com Jul 21 '10 at 4:18

This question came from our site for professional and enthusiast programmers.

    
I absolutally agree that doing it is the best way to learn, and I applaud your initative. However a web hosting company generally has someone who already knows what they're doing, because you don't want to lose everyone's data by accident because you're still learning - even if they haven't paid you any money for it. –  Mark Henderson Jul 21 '10 at 4:31
    
Sorry, I thought I posted it on server fault, and it is not really serious, it will be a free web host with small limits. –  Dr Hydralisk Jul 21 '10 at 4:55

4 Answers 4

I have used mod_bandwidth to restrict bandwidth. It can be used per directory, per file, etc... so, you just have to configure it per VirtualHost.

For the Disk Space, just use the quota. Create a unix account per customer, and assign them the quota. That should be quite well documented in the web.

share|improve this answer
    
But throttling bandwidth pushes load back onto the server - so you could end up with a DOS –  symcbean Nov 22 '11 at 10:33

Some quick Googling shows me that you could use a Squid proxy to set queues for data called 'data pools'. You can apparently also use IPROUTE2 and TC (can't post link, I'm not awesome enough)

From http://www.faqs.org/docs/Linux-HOWTO/Bandwidth-Limiting-HOWTO.html#AEN65

Apart from normal caching, Squid has a special feature called delay pools. Thanks to delay pools, it is possible to limit internet traffic in a reasonable way, depending on so-called 'magic words', existing in any given URL. For example, a magic word could be '.mp3', '.exe' or '.avi', etc. Any distinct part of a URL (such as .avi) can be defined as a magic word.

Also see an article on serverwatch.com titled Reining-in-Bandwidth-With-Squid-Proxying

Squid is probably the simplest way, and you can do a lot of other cool things with it, too.

share|improve this answer

Its not simple. I suspect that it won't be possible simply using vhosts to enforce limits unless you put a scripted proxy in front of the webserver (and that only addresses the bandwidth problem, unless you restrict file uploads to a scripted web interface).

But surely it makes more sense from a business point of view to sell a package which includes X bandwidth and Y disk usage then bill the customer for excesses (which you can measure easily from the disk footprint and the access logs).

C.

share|improve this answer
    
That doesn't work if the customer degrades service to other customers. Even if you bill for overages, you still usually need a limit. (Plus, your $50/year customer may balk at the $1,000 bill if they host a video that goes viral. So you usually still need a limit.) –  David Schwartz Nov 21 '11 at 21:20

To limit total bandwidth usage refer to the KikoV answer, I'm discussing about limiting disk space.

In fact there's no straight way to limit disk space, but you have two options:

  1. You can schedule a script which calculates used disk space for example every day and bans/alerts exceeded clients.
  2. You can create a system user for each of your clients and use the file system quota manager. Read this article for more information.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.