Is there a way in apache to limit the amount of users that can view a site in a certain month? I'd need to do this for individual vhosts.

Something along the lines of:

<VirtualHost *:80>
    ServerName website.com
    DocumentRoot "/var/www/website.com/public"
    **MONTHLY_USER_LIMIT** = 5000
</VirtualHost>

Is there anything in Apache that does this (or nginx) ?

Thanks!

link|improve this question

Interesting, but I don't see the point. Are you worried about server strain? You could change the max concurrent tcp connections: /proc/sys/net/core/somaxconn/ for concurrent connections and proc/sys/net/core/netdev_max_backlog for packet queue. – tjameson Apr 4 '11 at 17:13
This depends heavily on how you define a "user". One connection? One Keep-Alive connection? One "page view"? – nickgrim Apr 4 '11 at 19:13
It would be one unique IP (I understand that this could be several users within an organization) - would this have to be done in code? Or is there any way of doing it with a webserver? – kron Apr 5 '11 at 10:38
@tjameson - it's not a concern of server strain. It is to do with billing on a user/month basis. – kron Apr 5 '11 at 10:38
feedback

2 Answers

No, but you could configure the access log to go to a program that does the counting and then turns off a site. You'd have to make it resilient to apache restarts.

link|improve this answer
feedback

This is quite trivial if you're using something like PHP with Apache. You could implement the count manually on a per user basis using cookies (optimally), or if they have cookies disabled use something clever. This type of stuff belongs in a PHP script.

It seems that with a setup like yours, you probably have a user/password hash for authentication, so when they log in, log it. Every time they start a new session, log it. If they reach 5000 sessions, return a 401 error or something explaining that they have exceeded their per-month allotment of views.

If this truly is on a per-user basis, a server-side script would make the most sense. You don't even need to have a database, a simple text file will do the trick.

I'm pretty sure that a PHP script can access what host it is being accessed on (just look at the URL).

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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