Forum: NGINX returning a different response if memcache key is set

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Atif G. (Guest)
on 2009-02-04 02:24
(Received via mailing list)
Dear all,

A day ago, we had a DDOS attack.

To remedy that we have put some logic on the php application to check
of access on php per minute and if certain limit is matched do something
like "print 'please try later' and exit"

On the php side it will work fine but on the nginx side, it will still
forward all the request to the php-cgi to get that response.

What I would like to do in php side is something like

if limit reached,
key=hostname.locked, "Please try again later"

on nginx side.

If found memcached HTTP_HOST.locked, return someother file.

is that do-able.

best regards
Atif G. (Guest)
on 2009-02-04 02:42
(Received via mailing list)
perhaps I can explain better with code.

on the php side its like this
            $memcache = new Memcache;
            if (!$memcache->connect("", 11211) ) {
            //$host is HTTP_HOST variable.


            if ($memcache->get($host)) {
            } else {
                $memcache->set($host, 1, false, 60); # calculate how
requests per minute, expire after 60seconds
            if ($x>100) {
                $memcache->set($lock_key, 1, false, 60); # lock the
for 60 seconds

on nginx side i would like

if memcache get($http_host . lock){
  redirect to another page

best regards
This topic is locked and can not be replied to.